Javascript 기초-1
2024. 4. 10. 21:00ㆍReact native/JS (Javascript)
0. 출력
console.log()
1. String
string0 = "like this"
string1 = "this is a string"
string2 = 'single quotes and double quotes are equivalent'
string3 = `using backticks allow you to set arguments ${string0}` # template literal
2. const (boolean, integer, float)
const number = 999
const negative = -999
const fraction = .250
const b = true
3. let (dynamic typing)
let age # implicit declaration -> age doesnt exist
let age = undefined # same as above
let age = null # explicit declaration -> age not defined yet
4. Array
const fruits = new Array('apple', 'banana', 'cherry')
const fruits = ['apple', 'banana', 'cherry']
console.log(fruits)
console.log(fruits[1]) # 'banana'
console.log(fruits.length) # 3
5. 타입 분별법
console.log(typeof(fraction)) # number
console.log(typeof fraction) # number
6. 자바스크립트상의 계산오류
const n1 = 0.1
const n2 = 0.2
console.log(n1 + n2) # 0.30000000000000004
console.log( (n1 + n2).toFixed(1) ) # 0.3 (string)
7. Type conversion 및 casting
console.log( (n1+n2).toFixed(1) ) # 0.3 (string)
console.log( Number((n1+n2).toFixed(1)) ) # 0.3 (number)
'React native > JS (Javascript)' 카테고리의 다른 글
npm ERR! enoent ENOENT: no such file or directory, lstat (0) | 2024.04.03 |
---|