자바스크립트의 데이터 타입은 primitive type, object type, function 이 있다.
const num1 = 10; const size = 1.2; console.log(num1); // 10 console.log(size): //1.2
const infinity = 1 / 0; const negativeInfinity = -1 / 0; const notANumber = 'non' / 1; console.log(infinity); Infinity(양의 무한대) console.log(negativeInfinity); -Infinity(음의 무한대) console.log(notANumber); //NaN(Not a Number)
NaN
값이 출력된다.const char = 'c'; const brendan = 'brendan'; const greeting = 'hello ' + brendan; console.log(char); // c console.log(brendan); //brendan console.log(greeting); // hello brendan (string + 변수)
''
나 ""
를 통해 변수에 할당한다.string
과 다른 변수를 +
를 통해 또다른 변수에 할당할 수 있다.const canRead = true; const test = 3 < 1; console.log(canRead) // true console.log(test) //false
const name = "Yongmin" if(name) { //실행 }
const number = 100 if(number) { //실행 안됨 }
true
/false
값을 반환한다. (해당 조건을 평가 후 참인지 거짓인지 판단)
false
: 0, null, undefined, NaN(not a number), ''
true
: false
값을 제외한 모든 값
추가로 자바스크립트에서 if
조건문의 string
은 공백을 제외했을 때 모두 true
값을 반환하기 때문에 위와 같이 활용할 수 있다.
number의 경우, 연산자가 필수이다.
let nothing = null; console.log(nothing); // null
null
할당은 빈 값이라고 사용자가 직접 지정한 것이다. (빈 껍데기만 있는 느낌?)let a console.log(a) // undefined
null
과 달리 껍데기 조차 없음)const yongmin = { name: 'yongmin', age: 29 }; console.log(yongmin.name); // yongmin console.log(yongmin.age); // 29
key
, value
로 이루어진 객체
타입의 데이터(box-container)도 변수에 할당이 가능하다.const result = function () { const a = 10; console.log(a); }; result(); // 10
(first-class function)
함수 표현식(function expression)
이라고 한다.