1. "Variable" - 변수, rw(read/write)
let name = 'minsoo';
2. "Constant" - 변하지 않는 데이터 타입, r(read only)
const daysInWeek = 7;
3. "Variable types"
number
const count = 17; // integer
const size = 17.1; // decimal number
"typeof" - 변수 타입 확인하기
console.log(`value: ${count}, type: ${typeof count}`);
console.log(`value: ${size}, type: ${typeof size}`);
number - speicla numeric values: infinity, -infinity, NaN
const infinity = 1 / 0;
const negativeInfinity = -1 / 0;
const nAn = 'not a number' / 2;
bigInt - {(-2^53) ~ 2^53 }을 초과하는 범위
const bigInt = 1234567890123456789012345678901234567890n;
string
const brendan = 'brendan';
const greeting = 'hello ' + brendan;
console.log(`value: ${greeting}, type: ${typeof greeting}`);
const helloBob = `hi ${brendan}!`; //template literals (string)
console.log(`value: ${helloBob}, type: ${typeof helloBob}`);
console.log('value: ' + helloBob + ' type: ' + typeof helloBob);
boolean
const canRead = true;
const test = 3 < 1; // false
console.log(`value: ${canRead}, type: ${typeof canRead}`);
console.log(`value: ${test}, type: ${typeof test}`);
null
let nothing = null;
console.log(`value: ${nothing}, type: ${typeof nothing}`);
undefined
let x;
console.log(`value: ${x}, type: ${typeof x}`);
symbol
const symbol1 = Symbol('id');
const symbol2 = Symbol('id');
console.log(symbol1 === symbol2);
const gSymbol1 = Symbol.for('id');
const gSymbol2 = Symbol.for('id');
console.log(gSymbol1 === gSymbol2); // true
console.log(`value: ${symbol1.description}, type: ${typeof symbol1}`);
object, real-life object, data structure
const ellie = { name: 'ellie', age: 20 };
ellie.age = 21;
Dynamic typing: dynamically typed language
let text = 'hello';
console.log(text.charAt(0)); //h
console.log(`value: ${text}, type: ${typeof text}`);
text = 1;
console.log(`value: ${text}, type: ${typeof text}`);
text = '7' + 5;
console.log(`value: ${text}, type: ${typeof text}`);
text = '8' / '2';
console.log(`value: ${text}, type: ${typeof text}`);
console.log(text.charAt(0));