var은 function-scoped
let,const는 block-scoped 이다.
var num = 10;
var num = 20;
document.write(num);
let prices;
console.log(price);
//output : undefined
price = 350;
console.log(price);
//Output: 350
let meal = 'Enchiladas';
console.log(meal);
//Output: Enchiladas
meal = 'Burrito' ;
console.log(meal);
//Output: Burrito
const myName = 'Gilberto';
console.log(myName);
//Output: Gilberto
var로 변수값을 지정해주고 ``와 ${}을 활용해 아래와 같이 편리하게 사용할 수 있다.
var myName = "Daniel";
var myCity = 'Seoul';
console.log(`My name is ${myName}.My favorite city is ${myCity}`);
//OutPut: My name is Daniel. My favorite city is Seoul
typeof 를 활용하여 실시간으로 데이터타입을 알 수 있다.
let newVariable = 'Playing around with typeof.';
console.log(typeof newVariable);
newVariable = 1;
console.log(typeof newVariable);
//output: string
number