
<모던 JavaScript 튜토리얼 - 코어 자바스크립트>
https://ko.javascript.info/
// no error
let message = "hello";
message = 123456;
이처럼 변수에 저장되는 값의 타입을 언제든지 바꿀 수 있는 언어를 '동적 타입(dynamically typed)' 언어라고 부른다.
Infinity, -Infinity - 무한대alert( 1 / 0 ); - 어느 숫자든 0으로 나누면 무한대alert( Infinity ); - 직접 참조NaN - 계산 중 에러 발생alert( "숫자가 아님" / 2 );(253-1) = (9007199254740991) <= 숫자형 범위 <= -(253-1)BigInt는 길이의 상관없이 정수를 나타낼 수 있다.n을 붙이면 BigInt형const bigInt = 1234567890123456789012345678901234567890n;${…}에 변수나 표현식을 넣고 역 따옴표(``)로 감싸면 문자열 중간에 넣을 수 있다.let name = "John";
alert( `Hello, ${name}!` ); // Hello, John!
alert( `the result is ${1 + 2}` ); // the result is 3
char)True / Falsenull 값을 '존재하지 않는 객체에 대한 참조'로 사용null 값은 '존재하지 않는(nothing) 값', '비어 있는(empty) 값', '알 수 없는(unknown) 값'로 사용let age = null; //변수 age 값을 알 수 없거나 비어있음let age;
alert(age); // 'undefined'
age = undefined;
alert(age); // "undefined"
원시(primitive) 자료형 : 문자열이든 숫자든 한 가지만 표현 가능 (객체형 제외)
typeof xtypeof(x)typeof undefined // "undefined"
typeof 0 // "number"
typeof 10n // "bigint"
typeof true // "boolean"
typeof "foo" // "string"
typeof Symbol("id") // "symbol"
typeof Math // "object"
typeof null // "object"
typeof alert // "function"
Math는 수학 연산을 제공하는 내장 객체typeof null - 언어 자체의 오류typeof alert - 피연산자가 함수면 "function"반환 함수는 객체형에 속함. (함수형은 없음)
//아래 스크립트의 결과를 예측해 보세요.
let name = "Ilya";
alert( `hello ${1}` ); // hello 1
alert( `hello ${"name"}` ); // hello name
alert( `hello ${name}` ); // hello Ilya