230224 - ๋ณ€์ˆ˜ ํƒ€์ž…

๋ฐฑ์Šน์—ฐยท2023๋…„ 2์›” 24์ผ
1

๐Ÿšฉ ๋ณ€์ˆ˜ ํƒ€์ž…

number

๐Ÿ“ ์„ค๋ช…

  • ์ˆซ์ž๋ฅผ ๋‚˜ํƒ€๋‚ผ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ณ€์ˆ˜

โœ’๏ธ ์‚ฌ์šฉ๋ฒ•

์ž…๋ ฅ

let integer = 123; // ์ •์ˆ˜ - ์ˆซ์ž๋Š” ์•„๋ฌด๊ฑฐ๋‚˜ ์ „๋ถ€ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
let negative = -123; // ์Œ์ˆ˜
let double = 1.23; // ์‹ค์ˆ˜
let binary = 0b1111011; // 2์ง„์ˆ˜
let octal = 0o173; // 8์ง„์ˆ˜
let hex = 0x7b; //16์ง„์ˆ˜

// ์—ฐ์‚ฐ ๊ฐ€๋Šฅ
console.log(0 / 123); //0
console.log(123 / 0); //Infinity
console.log(123 / -0); //-Infinity
console.log(123 / "aa"); //NaN (Not a Number)

์ถœ๋ ฅ

  • ์ด๋ฏธ์ง€๋กœ ๋Œ€์ฒด



string

๐Ÿ“ ์„ค๋ช…

  • ๋ฌธ์ž์—ด์„ ๋‚˜ํƒ€๋‚ผ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ณ€์ˆ˜

โœ’๏ธ ์‚ฌ์šฉ๋ฒ•

์ž…๋ ฅ

let string = "์•ˆ๋…•ํ•˜์„ธ์š”";
string = `hello`;
console.log(string);

// ํŠน์ˆ˜๋ฌธ์ž ์ถœ๋ ฅํ•˜๋Š”๋ฒ•
string = "'๋”ฐ์˜ดํ‘œ๊ฐ€ ๋ณด์ด๊ฒŒ ์ถœ๋ ฅ'"; // ๋ณด์ด๊ณ  ์‹ถ์€ ๋”ฐ์˜ดํ‘œ๋ฅผ ์•ˆ์ชฝ์— ๋„ฃ๊ณ  ๋”ฐ์˜ดํ‘œ๋ฅผ ์ด์ค‘์œผ๋กœ("", '') ์ž‘์„ฑํ•˜๋ฉด ๋ณด์ž„
console.log(string);
string =  '๋˜‘๊ฐ™์€ \'๋”ฐ์˜ดํ‘œ\' ์‚ฌ์šฉ'; // ๋”ฐ์˜ดํ‘œ ์•ž๋ถ€๋ถ„์— ์—ญ์Šฌ๋ž˜์‹œ(\)๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐ™์€ ๋”ฐ์˜ดํ‘œ๋กœ๋„ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
console.log(string);
string = "โ— ์ค„๋ฐ”๊ฟˆ\n ํƒญํ‚ค ์‚ฌ์šฉ\t ๋ฐฑ์Šฌ๋ž˜์‹œ ๋‘๋ฒˆ\\    ์œ ๋‹ˆ์ฝ”๋“œ \u0d00 \n";  // ์ด์Šค์ผ€์ดํ”„ ํ‘œํ˜„
console.log(string);

/*
  ํ…œํ”Œ๋ฆฟ ๋ฆฌํ„ฐ๋Ÿด(Templete literal)
    - ๋‚ด์žฅ๋œ ํ‘œํ˜„์‹์„ ํ—ˆ์šฉํ•˜๋Š” ๋ฌธ์ž์—ด ๋ฐฉ๋ฒ•
    - ๋”ฐ์˜ดํ‘œ ๋Œ€์‹  ๋ฐฑํ‹ฑ ์‚ฌ์šฉ, ${๋ณ€์ˆ˜}
*/
let id = "Rainy";
let greetings = "์•ˆ๋…•ํ•˜์„ธ์š” " + id + "๋‹˜ \n์ฆ๊ฑฐ์šด ํ•˜๋ฃจ ๋ณด๋‚ด์„ธ์š”";
console.log(greetings, "-์ „ํ†ต์ ๋ฐฉ๋ฒ•\n");


greetings = `์•ˆ๋…•ํ•˜์„ธ์š” ${id}๋‹˜ ์ฆ๊ฑฐ์šด    ํ•˜๋ฃจ ๋ณด๋‚ด์„ธ์š”`;
console.log(greetings, "-ํ…œํ”Œ๋ฆฟ ๋ฆฌํ„ฐ๋Ÿด");
console.log("");

console.log("1 + 1 = 2");
console.log(`1 + 1 = ${1 + 1}`);  // 1 + 1 = 2

์ถœ๋ ฅ

  • ์ด๋ฏธ์ง€๋กœ ๋Œ€์ฒด



boolean

๐Ÿ“ ์„ค๋ช…

  • boolean ํƒ€์ž…. true/false๋ฅผ ๋‚˜ํƒ€๋‚ผ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ๋ณ€์ˆ˜

โœ’๏ธ ์‚ฌ์šฉ๋ฒ•

์ž…๋ ฅ

/* 
  boolean ํƒ€์ž… - true/false
*/

let aa = true; // ๋ฌธ์ž์ง€๋งŒ ๋”ฐ์˜ดํ‘œ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์œผ๋ฉด boolean
console.log("๋ณ€์ˆ˜ aa๋Š”", aa);
console.log("๋ณ€์ˆ˜ aa๋Š”", !aa); // not์—ฐ์‚ฐ์ž(!)
console.log(0);
console.log(!0); // 0์ด ์•„๋‹˜ - true

console.log(""); // ํ•œ์ค„ ๊ณต๋ฐฑ ์ค„๋ฐ”๊ฟˆ

//falsy ๊ฑฐ์ง“์ธ ๊ฐ’ ๊ฐ’ ์•ž์— '!!'๋ฅผ ๋ถ™์ด๋ฉด ๋ฌด์กฐ๊ฑด boolean(false)์œผ๋กœ ๋ณ€ํ•จ
console.log("============= falsy ๊ฑฐ์ง“์ธ ๊ฐ’ =============");

console.log(!!0);
console.log(!!-0);
console.log(!!"");
console.log(!!null); 
console.log(!!undefined);
console.log(!!NaN);

console.log("");

// truthly ์ฐธ์ธ ๊ฐ’
console.log("============= truthly ์ฐธ์ธ ๊ฐ’ =============");
console.log(1);
console.log(-1);
console.log("๋ฌธ์ž์—ด");
console.log({}); // ๋น„์–ด์žˆ๋Š” ์˜ค๋ธŒ์ ํŠธ
console.log([]); // ๋น„์–ด์žˆ๋Š” ๋ฐฐ์—ด
console.log(Infinity);

console.log("");

// ์‘์šฉ
console.log("============= ์‘์šฉ =============");
let bb;
console.log("๋ณ€์ˆ˜ bb๋Š”?", !!bb);
console.log(3 < 2);
console.log(3 == 2);
console.log(3 > 2);

์ถœ๋ ฅ

  • ์ด๋ฏธ์ง€๋กœ ๋Œ€์ฒด



empty (null, undefined)

๐Ÿ“ ์„ค๋ช…

  • ๊ฐ’์ด ์—†๋Š” ์ƒํƒœ๋ฅผ ๋‚˜ํƒ€๋‚ด๊ธฐ ์œ„ํ•œ ๋ณ€์ˆ˜

โœ’๏ธ ์‚ฌ์šฉ๋ฒ•

์ž…๋ ฅ

// null, undefiend

let vari;
console.log(vari); // undefined ๋ฉ”๋ชจ๋ฆฌ์ƒ ์–ด๋–ค ๋ฐ์ดํ„ฐ๋„ ๋“ค์–ด์žˆ์ง€ ์•Š์Œ
vari = null; // ๋ณ€์ˆ˜๊ฐ€ ๋น„์–ด์žˆ๋‹ค๊ณ  ์„ ์–ธ
console.log(vari);

console.log("");

let activeItem; // ๋ณ€์ˆ˜ ์„ ์–ธ, undefined ์ƒํƒœ
console.log("๋ณ€์ˆ˜ activeItem : ", activeItem);
activeItem = null;
console.log("null activeItem : ", activeItem);

console.log("typeof null : ", typeof null); 
// ์ถœ๋ ฅ ๊ฒฐ๊ณผ - object : ๋น„์–ด์žˆ๋‹ค๋Š” ์˜๋ฏธ๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— null์€ type์ด object๋กœ ์ถœ๋ ฅ
// typeof : ๋ณ€์ˆ˜์˜ ์ž๋ฃŒํ˜•์ด ๋ฌด์—‡์ธ์ง€ ์•Œ๋ ค์คŒ

์ถœ๋ ฅ

  • ์ด๋ฏธ์ง€๋กœ ๋Œ€์ฒด


๐Ÿ”— ์ฐธ๊ณ  ๋งํฌ & ๋„์›€์ด ๋˜๋Š” ๋งํฌ






profile
๊ณต๋ถ€ํ•˜๋Š” ๋ฒจ๋กœ๊ทธ

0๊ฐœ์˜ ๋Œ“๊ธ€