๋ ธ๋ง๋์ฝ๋์ ํฌ๋กฌ ์ฑ ๋ง๋ค๊ธฐ ํด๋ก ์ฝ๋ฉ์ ๋๋ค.
console.log(12345);
console.log("hongsi");
๋ณ์ ์ ์ธํ ๋
const - always
let - sometimes
var - never
const ์ฌ์ ์ธ ๊ธ์ง, ์ฌํ ๋น ๊ธ์ง
let ์ฌ์ ์ธ ๊ธ์ง, ์ฌํ ๋น ๊ฐ๋ฅ
var ์ฌ์ ์ธ ๊ฐ๋ฅ, ์ฌํ ๋น ๊ฐ๋ฅ
const a = b;
const a = c;
//์ฌ์ ์ธ ๊ธ์ง
const a = b;
a = c;
//์ฌํ ๋น ๊ธ์ง
let a = b;
let a = c;
//์ฌ์ ์ธ ๊ธ์ง
let a = b;
a = c;
//์ฌํ ๋น์ ๊ฐ๋ฅ
var a = b;
var a = c;
a = d;
//์ฌ์ ์ธ, ์ฌํ ๋น ๊ฐ๋ฅ
booleans
true, false,
null = ์๋ฌด๊ฒ๋ ์์(๊ฐ์ ์ฃผ์ด์ง) (์ ๋ ์์ฐ์ ์ผ๋ก ๋ฐ์ํ์ง ์๋๋ค)
undefined = variable์ด ์กด์ฌํ๋๋ฐ ๊ฐ์ด ์ฃผ์ด์ง์ง ์์ ๊ฒ
array
const daysofweek = ["mon" , "tue" , "wed" , "thu" , "fri" , "sat"];
// get item from array
console.log(daysofweek[0]);
// add one more day to the array
daysofweek.push("sun");
objects์ ๋ฐ์ดํฐ ์ ์ฅํ๊ธฐ
const player = {
name: "halee",
points: 121212,
handsome: true,
fat: true
}
console.log(player);
{name: "halee", points: 121212, handsome: true, fat: true}
object ์์ ํน์ ๊ฐ ์ถ๋ ฅํ๊ธฐ
console.log(player.name);
console.log(player["name"]);
// same
halee
object ๋ด์ฉ ์์ ํ๊ธฐ
const player = {
name: "halee",
points: 121212,
handsome: true,
fat: true
}
console.log(player);
player.fat = false;
console.log(player);
{name: "halee", points: 121212, handsome: true, fat: true} (app.js, line 7)
{name: "halee", points: 121212, handsome: true, fat: false} (app.js, line 11)
**object ์์ ๋ด์ฉ์ ์์ ํ๋ ๊ฒ์ด๋ผ์ const ์จ๋ ๋ด์ฉ ์ ๋ฐ์ดํธ ๊ฐ๋ฅ!! (object(์ฌ๊ธฐ์๋ player)๋ ๋์ผ)
object์ ํญ๋ชฉ ์ถ๊ฐํ๊ธฐ
const player = {
name: "halee",
points: 121212,
handsome: true,
fat: true
}
console.log(player);
player.lastname = "potato";
console.log(player);
{name: "halee", points: 121212, handsome: true, fat: true} (app.js, line 7)
{name: "halee", points: 121212, handsome: true, fat: true, lastname: "potato"} (app.js, line 11)
object ํญ๋ชฉ ์ ๋ฐ์ดํธ ํ๊ธฐ
const player = {
name: "halee",
points: 10,
handsome: true,
fat: true
}
console.log(player.points);
player.points = player.points + 15;
console.log(player.points);
10
25