value-number-string-boolean-null-undefined

์‹œ์ž‘ํ•˜๊ธฐ ์ „์—

  • ๊ธฐ๋Šฅ ๊ตฌํ˜„ ์—๋งŒ ์ง‘์ค‘

  • ์ธ๋‚ด์‹ฌ์„ ๊ธฐ๋ฅธ๋‹ค.

  • ์งˆ๋ฌธ์„ ํ•˜๊ธฐ ์ „์— ๋ฐ˜๋“œ์‹œ ๊ผผ๊ผผํ•˜๊ฒŒ ์กฐ์‚ฌํ•ด๋ณด๊ณ  ๊นŠ๊ฒŒ ์ƒ๊ฐํ•ด๋ณด๋Š” ์‹œ๊ฐ„์„ ๊ฐ–๋Š”๋‹ค.

  • ์ตœ๋Œ€ํ•œ ์Šค์Šค๋กœ ํ•ด๊ฒฐํ•˜๋„๋ก ๋…ธ๋ ฅํ•œ๋‹ค.

  • ์˜์–ด๋ฅผ ๋‘๋ ค์›Œ ํ•˜์ง€๋งˆ๋ผ

  • ๊ฐ™์€ ์‹ค์ˆ˜๋ฅผ ๋ฐ˜๋ณตํ•˜์ง€ ์•Š๊ธฐ

  • ๊ณต๋ถ€ํ•œ ๋‚ด์šฉ์„ ๊ธฐ๋กํ•œ๋‹ค.

  • ์ฝ”๋“œ๋Š” ์‚ฌ๋žŒ์ด ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด ์“ฐ๋Š”๊ฒƒ. ์ข‹์€ ์ฝ”๋“œ๋ฅผ ์“ฐ๋„๋ก ํ•˜์Ÿˆ 'ใ…'

Table of Contents

value

var catAge = 7;
  • ๊ฐ’์ด๋‹ค.

  • ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋ฅผ ์“ฐ๊ฒŒ๋˜๋ฉด ๊ฐ’์„ ๋‹ค๋ฃจ๊ณ  ๋„˜๊ธฐ๊ณ  ๋ฐ›๊ธฐ

  • ํ•œ๊ธ€์ž๋„ ๋‹ค ์•Œ๊ณ  ์จ๋ผ

  • ์นด๋ฉœ์ผ€์ด์Šค๋ฅผ ์ถ”์ฒœ

Type

console.log(typeof 1); //"number"
  • ๋ฌธ์ž์—ด(์ŠคํŠธ๋ง์œผ๋กœ)๋กœ number๊ฐ€ ๋‚˜์˜จ๋‹ค.

  • ๋ชจ๋“ ๊ฑธ ๋ฌธ์ž์—ด๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

Available types in Javascript

  • String Type

  • Number Type

  • Boolean Type

  • Null Type

  • Undefined Type

  • Object Type

  • Symbol Type (new in ES2015)

Number

isInteger

์ •์ˆ˜์ธ์ง€ ํŒ๋ณ„ํ›„ true / false ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

Number.isInteger(0);         // true
Number.isInteger(1);         // true
Number.isInteger(-100000);   // true
Number.isInteger(99999999999999999999999); // true

Number.isInteger(0.1);       // false
Number.isInteger(Math.PI);   // false

Number.isInteger(NaN);       // false
Number.isInteger(Infinity);  // false
Number.isInteger(-Infinity); // false
Number.isInteger('10');      // false
Number.isInteger(true);      // false
Number.isInteger(false);     // false
Number.isInteger([1]);       // false

Arithmetic_Operators

Addition (+)

// Number + Number -> addition
1 + 2 // 3

// Boolean + Number -> addition
true + 1 // 2

// Boolean + Boolean -> addition
false + false // 0

์ฐธ๊ณ  MDN

Exponentiation (**)

a ** b // a์˜ 3์ œ๊ณฑ

comparison operators

8 === 8;
8 !== 9;

์ตœ๋Œ€ํ•œ 3๊ฐœ๋ฅผ ์“ฐ๋„๋ก ํ•œ๋‹ค.

Special numbers

NaN
-0
Infinity
-Infinity

๊ฐ’์„ ํ‘œ๊ธฐํ•ด์ฃผ๋Š” ํŠน๋ณ„ํ•œ ํ‚ค์›Œ๋“œ์ธ๋ฐ ์ˆซ์ž๋‹ค.

NaN

0 / 0; //NaN
1 * 'hello'; //NaN 

console.log(typeof NaN); //"number"
NaN === NaN //true

String

comparison

'a' < 'b'; // true
'aaa' < 'abc'; // treu
'a' < 'Z'; // false
'ํ•œ๊ธ€' < 'ํ•œ๊ตญ์–ด'; // false
'2' < '10'; // false

๋ฌธ์ž์—ด๋ผ๋ฆฌ ๋น„๊ต๊ฐ€ ๊ฐ€๋Šฅํ•˜๋‹ค.

Characteristics

Stringโ€‹.prototypeโ€‹.concat()

'hello'.concat('fun', 'javascript'); //"hellofunjavascript"

Stringโ€‹.prototypeโ€‹.concat() MDN

๋ฌธ์ž์—ด์€ ์ธ๋ฑ์Šค ์œ„์น˜๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋‹ค.

var a = 'hello'
console.log(a[3]); // l

๋ฌธ์ž์—ด์€ ์ธ๋ฑ์Šค ์œ„์น˜๋กœ ์ด๋ฏธ ๋งŒ๋“ ๊ฑธ ๋„ฃ์„ ์ˆ˜ ์—†๋‹ค.

var a = 'hello'
a[3] = 'o';
console.log(a); //"hello"

์ธ๋ฑ์Šค 3๋ฒˆ์งธ ์œ„์น˜์— o๊ฐ€ ์œ„์น˜ํ•˜์ง€ ์•Š๊ณ  ๊ทธ๋Œ€๋กœ l์ด ์œ„์น˜ํ•œ๋‹ค.

Boolean

Truthy & Falsy

undefined;
null;
0;
-0;
NaN;
false;
'';
"";

๊ณต๋ฐฑ์กฐ์ฐจ ์—†๋Š” ๋นˆ ๋ฌธ์ž์—ด์ด์—ฌ์•ผ ํ•œ๋‹ค

์ด ๊ฐ’์„ ์ œ์™ธํ•˜๊ณค ๋ชจ๋‘ true

null & undefined

undefined

  • ์–ด๋–ค ๋ณ€์ˆ˜์˜ ๊ฐ’์ด ์•„์ง ํ• ๋‹น๋˜์–ด์ง€์ง€ ์•Š์•˜์Œ์„ ์˜๋ฏธ

  • ์ง์ ‘ undefined๋ฅผ ํ• ๋‹นํ•˜๋Š” ๊ฒฝ์šฐ๋Š” ์—†์–ด์•ผ ํ•œ๋‹ค.

null

  • ์—†๋Š” ๊ฐ’

  • ์žˆ๋‹ค๊ฐ€ ์—†์–ด์ง„ ๊ฐ’์ผ ์ˆ˜๋„ ์žˆ๊ณ , ์• ์ดˆ์— ์—†์„ ์ˆ˜๋„ ์žˆ๋‹ค.

  • ์—†๋Š” ๊ฐ’์„ ๋‚˜ํƒ€๋‚ด๊ณ  ์‹ถ์„๋•Œ ํ”„๋กœ๊ทธ๋ž˜๋จธ๋Š” undefined๋ฅผ ๋„ฃ์ง€ ๋ง๊ณ  null๊ฐ’์„ ์ž…๋ ฅํ•œ๋‹ค.

typeof(null); //object ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ mistake ์ด์Šˆ์žˆ์Œ

Last updated

Was this helpful?