2019. 04. 06
๊ถ๊ธฐ์
์๋ฐ์คํฌ๋ฆฝํธ์ ๊ฐ์ ์ฌ์ฏ๊ฐ์ง ๊ธฐ๋ณธ ์๋ฃํ๊ณผ Object๋ก ๊ตฌ์ฑ๋ฉ๋๋ค
String, Number, Boolean, null, undefined, Symbol
๊ฐ์ฒด๋ ๊ณ ์ ํ๊ธฐ ๋๋ฌธ์, ์์ ๊ณผ์ ๋น๊ต์์๋ง ์ผ์น ํฉ๋๋ค
๋ฐ๋ฉด, ์์๊ฐ์ ๊ฐ์ด ๊ฐ์ผ๋ฉด ๊ฐ์ ๊ฒ์ผ๋ก ํ๊ฐํฉ๋๋ค
์์๊ฐ์ ๊ฐ์ ํ๋ฉฐ, ํญ์ ๋ถ๋ณ์ ๋๋ค
"๊ฐ์ผ๋ก ๋น๊ต"
"์ ๋ณด๊ฐ ์์"์ ๋ํ๋ด๋ ๊ฐ
undefined, null
๊ฐ ์์ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ
undefined, null
์ ์ญ์ฌ
undefined, null
์์ ๊ฐ / ๊ฐ์ฒด ๊ฐ ์ผ๋ก ๋ถ๋ฆฌํ๋ Java ์ ์ ๊ทผ๋ฒ์ ์ฐจ์ฉ ํ์ต๋๋ค
๊ทธ๋ฆฌ๊ณ "๊ฐ์ฒด ์๋" ์ ํํํ๋ ๊ฐ์ธ null ๋ํ ๋์ ํ์ต๋๋ค
ํ์ง๋ง, C ์ธ์ด ๊ณํต์ JavaScript ๋ null ์ ์ซ์๋ก ๊ฐ์ ํ๋ฉด 0์ด ๋ฉ๋๋ค
์ ์ญ์ฌ
undefined, null
undefined ๋ null ์ดํ์ ์ถ๊ฐ ๋์์ต๋๋ค
null ๋ก "์ด๊ธฐํ ๋์ง ์์ ๋ณ์" ๋๋ "์กด์ฌํ์ง ์๋ ํ๋กํผํฐ" ์ ๋ํ ์ฒ๋ฆฌ๋ฅผ ํ์ง๋ง
null ์ ํ๋์ ๊ฐ์ด๊ณ , null ์ด๋ผ๋ ๊ฐ์ NULL Pointer ์ reference ์ ๋๋ค
๋ฐ๋ผ์, ๋ธ๋๋ ์์ดํฌ๋ ์๋์ ๊ฒฝ์ฐ๋ฅผ ํผํ๊ณ ์ถ์์ต๋๋ค
๊ทธ๋ฆฌํ์ฌ, "์ด๊ธฐํ ๋์ง ์์ ๋ณ์" ๋๋ "์กด์ฌํ์ง ์๋ ํ๋กํผํฐ" ๋
์์ฑ(์ ๊ทผ) ์์ ์ undefined๊ฐ ํ ๋น๋ฉ๋๋ค
์ฌ๋ด
undefined, null
1. undefined๋ ECMAScript5 ์ดํ ์ฝ๊ธฐ ์ ์ฉ์ผ๋ก ์ฌ ํ ๋น์ด ๋ถ๊ฐํฉ๋๋ค
(ECMAScript3 ์์๋ undefined ๊ฐ์ ๋ฎ์ด์ธ ์ ์์ต๋๋ค)
2. undefined๋ ์ ์ญ ๊ฐ์ฒด์ ํ๋กํผํฐ์ด๋ฉฐ, undefined ์์ ๊ฐ์ ๊ฐ์ง๋๋ค
3. void 0 ๋ ํญ์ undefined ๋ฅผ ๋ฐํํฉ๋๋ค
4. ๋ณด๋ค ์์ธํ ๋ด์ฉ์ ์๋ ๋งํฌ๋ค์ ์ฐธ๊ณ ํ์ธ์
โ ECMAScript 1.3
โ The history of "typeof null"
โ V8 Document
์ฐ์ง๋ง์ธ์
๋ํผ ๊ฐ์ฒด๋ ์์ ๊ฐ๊ณผ ๋ค๋ฆ ๋๋ค
์์ ๊ฐ์ ๋ํผ ๊ฐ์ฒด์ prototype ์ฒด์ธ์ ๊ณต์ ํฉ๋๋ค
๋ํผ ๊ฐ์ฒด๋ฅผ ์์ ๊ฐ์ผ๋ก, ์์ ๊ฐ์ ๋ํผ ๊ฐ์ฒด๋ก ๋ฐ๊พธ๊ธฐ
PrimitiveWrapper(primitiveValue)
PrimitiveWrapper.valueOf()
๊ทธ ์ ์, falsy ํ ๊ฐ์ ์์์ผ ํฉ๋๋ค
undefined, null, false, 0, NaN, '' (๋น ๋ฌธ์์ด)
๊ฐ์ฒด๋ฅผ ์์ ๊ฐ์ผ๋ก ๋ณํํ๊ธฐ
valueOf - ๋ํผ ๊ฐ์ฒด๋ฅผ ์์ ๊ฐ์ผ๋ก ๋ณํํ๊ธฐ
falsy ๊ฐ์ Boolean, Number, String ์ผ๋ก ๋ฐ๊ฟ ๊ฒฝ์ฐ
ToPrimitive ์ ๊ทธ ๋์ ์ดํดํ๊ธฐ
ToPrimitive ๋ ์ถ์ ์ฐ์ฐ์(Abstract Operations) ๋ก input ์ non Object ์ ํ์ผ๋ก ๋ณํํ์ฌ ๋ฐํํฉ๋๋ค
signature
ToPrimitive ์ ๊ทธ ๋์ ์ดํดํ๊ธฐ
ToPrimitive ๋ ๋ชจ๋ ํ ๋ณํ ๋์์ ์ถ์์ด๋ฉฐ
parseInt, .toJSON ๋ฑ ์ฌ๋ฌ ํ ๋ณํ ๋์์ ์กฐ์์ ๋๋ค
ํ ๋ณํ์ด ๋ ๋๋ ์๋ ์์๋๋ก...
1. input ์ด ์์ ๊ฐ์ด๋ฉด ๊ทธ๋๋ก ๋ฐํํฉ๋๋ค
2. input ์ด ๊ฐ์ฒด๋ผ๋ฉด, input.valueOf ๋ฅผ ํธ์ถํ์ฌ ์์๊ฐ์ด๋ฉด ๋ฐํํฉ๋๋ค
3. valueOf ์ ๊ฐ์ด ์์๊ฐ์ด ์๋๋ผ๋ฉด, toString ์ ํธ์ถํฉ๋๋ค. ์์๊ฐ์ด๋ฉด ๋ฐํํฉ๋๋ค
4. 2-3๋ฒ ๊ณผ์ ์์ return ์ด ์ผ์ด๋์ง ์์ผ๋ฉด, TypeError๋ฅผ throw ํฉ๋๋ค
1. input ์ด ์์ ๊ฐ์ด๋ฉด ๊ทธ๋๋ก ๋ฐํํฉ๋๋ค
2. input ์ด ๊ฐ์ฒด๋ผ๋ฉด, input.valueOf ๋ฅผ ํธ์ถํ์ฌ ์์๊ฐ์ด๋ฉด ๋ฐํํฉ๋๋ค
3. valueOf ์ ๊ฐ์ด ์์๊ฐ์ด ์๋๋ผ๋ฉด, toString ์ ํธ์ถํฉ๋๋ค. ์์๊ฐ์ด๋ฉด ๋ฐํํฉ๋๋ค
4. 2-3๋ฒ ๊ณผ์ ์์ return ์ด ์ผ์ด๋์ง ์์ผ๋ฉด, TypeError๋ฅผ throw ํฉ๋๋ค
์๋ฐ์คํฌ๋ฆฝํธ์ ๋ชจ๋ ์ฐ์ฐ์๋ ํผ์ฐ์ฐ์๋ฅผ ์ ์ ํ ํ์ ์ผ๋ก ๊ฐ์ ํฉ๋๋ค
Operand
Primitive Value
์๋๋ฉด, ์๋ฐ์คํฌ๋ฆฝํธ์ ์ฐ์ฐ์๋ ๋๋ถ๋ถ ์์๊ฐ์ผ๋ก ์กฐ์๋๊ฑฐ๋ ์
Primitive Value
1. ์๋ฐ์คํฌ๋ฆฝํธ์ ์ฐ์ฐ์๋ ํผ ์ฐ์ฐ์์ ๊ฐ์ ์์๊ฐ์ผ๋ก ๊ฐ์ ํ๋ค
2. ์์๊ฐ์ด ์๋ ๊ฒฝ์ฐ, ์์๊ฐ์ผ๋ก ๋ฐ๊พผ๋ค
3. ์์๊ฐ์ ํ์ ์ ๋ง์ถ๋ค!
์ด๋ ๊ฒ ๋๋ด๊ณ ์ถ์ง๋ง...
์ค๋์ ์ผํฌํธ ๊น๊ธฐ์ ์ง์
์ฐ์ฐ์๋ก ๊ฐ์ฒด๋ ๋ค๋ฃฐ ์ ์๋ ์ธ์ด๋ ์์ต๋๋ค
PHP
C++
์๋ฌดํผ ์๋ฐ์คํฌ๋ฆฝํธ๋ ์๋ฉ๋๋ค. ํด ๋ณผ๊น์?
๋์ ์ฐ์ฐ์, ๋น๊ต ์ฐ์ฐ์, ์ฐ์ ์ฐ์ฐ์, ๋นํธ๋จ์ ์ฐ์ฐ์, ๋ ผ๋ฆฌ ์ฐ์ฐ์, ๋ฌธ์์ด ์ฐ์ฐ์, ์กฐ๊ฑด (์ผํญ) ์ฐ์ฐ์, ์ฝค๋ง ์ฐ์ฐ์, ๋จํญ ์ฐ์ฐ์, ๊ด๊ณ ์ฐ์ฐ์
๋์ ์ฐ์ฐ์, ๋น๊ต ์ฐ์ฐ์, ์ฐ์ ์ฐ์ฐ์, ๋นํธ๋จ์ ์ฐ์ฐ์, ๋ ผ๋ฆฌ ์ฐ์ฐ์, ๋ฌธ์์ด ์ฐ์ฐ์, ์กฐ๊ฑด (์ผํญ) ์ฐ์ฐ์, ์ฝค๋ง ์ฐ์ฐ์, ๋จํญ ์ฐ์ฐ์, ๊ด๊ณ ์ฐ์ฐ์
๋์ ์ฐ์ฐ์ [ = ]
๋์ ์ฐ์ฐ์๋ฅผ ์ค๋ช ํ๊ธฐ ์ ์
์๋ฐ์คํฌ๋ฆฝํธ์ ๋ฌธ(Statement)๊ณผ ์(Expression) ์ ๋ํด์ ์๊ณ ๊ณ์๋์?
๐ MDN Expression and operators
An expression is any valid unit of code that resolves to a value.
์์ด๋ ๊ฐ์ผ๋ก ํด์(resolves)๋ ์ ์๋ ์ ํจํ ์ด๋ค ์ฝ๋์ ๋จ์ ์ ๋๋ค
Every syntactically valid expression resolves to some value but conceptually, there are two types of expressions: with side effects
(for example: those that assign value to a variable) and those that in some sense evaluate and therefore resolve to a value.
๋ชจ๋ ๊ตฌ๋ฌธ์ ์ผ๋ก ์ ํจํ ์์ ๊ฐ์ผ๋ก ํด์(resolves) ๋๊ณ , ๊ฐ๋ ์ ์ผ๋ก๋ ๋ ์ข ๋ฅ์ ์์ด ์กด์ฌํฉ๋๋ค:
side effects(๋ณ์์ ๊ฐ์ ํ ๋นํ๋ ํํ์) ์ ํ๊ฐํ์ฌ ๊ฐ์ผ๋ก ํด์๋๋ ๊ฐ
The expression x = 7 is an example of the first type.
This expression uses the = operator to assign the value seven to the variable x. The expression itself evaluates to seven.
x = 7 ์ด๋ผ๋ ์์ ์ฒซ ๋ฒ์งธ(side effect) ์์ ์ ๋๋ค
์ด ์์ " = " ์ฐ์ฐ์๋ฅผ ์ฌ์ฉํ์ฌ 7์ด๋ผ๋ ๊ฐ์ x ๋ผ๋ ๋ณ์์ ํ ๋นํ์ต๋๋ค. ์ด ์์ ์ด๊ฒ ์์ฒด๋ก 7 ๋ก์จ ํ๊ฐ๋ฉ๋๋ค
The code 3 + 4 is an example of the second expression type.
This expression uses the + operator to add three and four together without assigning the result, seven, to a variable.
3 + 4 ๋ผ๋ ์ฝ๋๋ ๋ ๋ฒ์งธ(some sense evaluate and therefore resolve to a value) ์์ ์ ๋๋ค
์ด ์์ " + " ์ฐ์ฐ์๋ฅผ ์ฌ์ฉํ์ฌ 3๊ณผ 4๋ฅผ ์๋ก ๋ํ์ง๋ง, 7 ์ด๋ผ๋ ๊ฒฐ๊ณผ๋ฅผ ํ ๋น ํ์ง๋ ์์์ต๋๋ค
๋์ ์ฐ์ฐ์ [ = ]
์๊ณผ ๋ฌธ์ ๋ํ ์ดํด๋ฅผ ํ๋๋ก ๋์์ฃผ์ ์ฝ๋๋๋์ด ์ ์๋์ ์ข์ ๊ธ
๋์ ์ฐ์ฐ์ [ = ]
์ฐ์ฐ์๋ฅผ ์ฌ์ฉํ๋ฉด, ์์ผ๋ก ํ๊ฐ๋๋ค๊ณ ํ๋
๋์ ์ฐ์ฐ์ ๋ํ ํ๋์ ์์ด์ ๊ฐ ์ ๋๋ค
๋์ ์ฐ์ฐ์ [ = ]
ํ ๋น ์์ฒด๋ง์ผ๋ก๋ ํ๋์ ๋ฌธ์ด ์๋ ์์ด๋ผ๋ ์๋ฏธ!
๋์ ์ฐ์ฐ์ [ = ]
let, const, var ๋ผ๋ ํค์๋๋
if, else, for ๋ฑ๊ณผ ๊ฐ์ด ๋ฌธ์ผ๋ก ๋ง๋ค์ด ์ฃผ๋ Keyword ์ ๋๋ค
๋์ ์ฐ์ฐ์ [ = ]
๋์ ์ฐ์ฐ์๋ ์ (Expression) ์ด๊ธฐ ๋๋ฌธ์
์ด๋ฐ๊ฒ ๊ฐ๋ฅํ๋ ๊ฒ์ด์ ธ ใ ใ ใ
ํน์ ๋ค ์์ จ๋๊ฑด ์๋์ฃ ...?
๋ณตํฉ ๋์ ์ฐ์ฐ์ [ OP= ]
๋ณตํฉ ๋์ ์ฐ์ฐ์๋ ๋์ ์ฐ์ฐ์์ ๊ฐ๋ฏธ๋ฃ๋ฅผ ์ถ๊ฐํ์ต๋๋ค (Syntactic Sugar)
๋ณตํฉ ๋์ ์ฐ์ฐ์ [ OP= ]
Syntactic Sugar ๋ผ๋ ์๋ฏธ๋, ๋จ์ํ ์ถ์ฝ ๊ตฌ๋ฌธ ์ด๋ผ๋ ์๋ฏธ ์ ๋๋ค!
(๋ฑ์ด ๋ง์ค์ฝํธ์ธ ์ด๋ค ์ธ์ด์ฒ๋ผ ์ํฉ์ ๋ฐ๋ผ ํ ๋น์ด ๋ค๋ฅด์ง ์์ต๋๋ค)
๋ณตํฉ ๋์ ์ฐ์ฐ์ [ OP= ]
[ OP= ] ์ด๋ผ๋ ์๋ฏธ๋ = ์์ [์ฐ์ , ๋นํธ] ์ฐ์ฐ์๋ฅผ ์ธ ์ ์๋ค๋ ๋ป
[์ฐ์ ] ๋ณตํฉ ๋์ ์ฐ์ฐ์
๋ง์
๋์
โ (x += y) == (x = x + y)
๋บ์
๋์
โ (x -= y) == (x = x - y)
๊ณฑ์
๋์
โ (x *= y) == (x = x * y)
๋๋์
๋์
โ (x /= y) == (x = x / y)
๋๋จธ์ง ์ฐ์ฐ ๋์
โ (x %= y) == (x = x % y)
[๋นํธ] ๋ณตํฉ ๋์ ์ฐ์ฐ์
์ผ์ชฝ ์ด๋ ์ฐ์ฐ ๋์
โ x <<(x <<= y) == (x = x << y)
์ค๋ฅธ์ชฝ ์ด๋ ์ฐ์ฐ ๋์
โ (x >>= y) == (x = x >> y)
๋ถํธ ์๋ ์ค๋ฅธ์ชฝ ์ด๋ ์ฐ์ฐ ๋์
โ (x >>>= y) == (x = x >>> y)
๋นํธ ๋จ์ ๋
ผ๋ฆฌ๊ณฑ ์ฐ์ฐ ๋์
โ (x &= y) == (x = x & y)
๋นํธ ๋จ์ ๋ฐฐํ์ ๋
ผ๋ฆฌํฉ ์ฐ์ฐ ๋์
โ (x ^= y) == (x = x ^ y)
๋นํธ ๋จ์ ๋
ผ๋ฆฌํฉ ์ฐ์ฐ ๋์
โ (x |= y) == (x = x | y)
๋ณตํฉ ๋์ ์ฐ์ฐ์ [ OP= ]
๋๋ฑ ๋น๊ต ์ฐ์ฐ์ [ ==, !=, ===, !== ]
์ค๋ช ์ด ๊ธธ์ด์ง ๊ฒ ๊ฐ์์...
3์ค ์์ฝ โ
1. == ์ฐ์ฐ์์ === ์ฐ์ฐ์์ ๋์ ๋ฐฉ์์ ๊ฐ์ฅ ํฐ ์ฐจ์ด์ ์ ํ์ ์ ๋ณํํ๋๊ฐ ์ ๋๋ค
2. === ์ฐ์ฐ์๋ ๊ฐ๊ณผ ํ์ ๊น์ง ๊ฐ์์ผ ํฉ๋๋ค
3. == ์ฐ์ฐ์๋ ๊ฐ์ ํ์ ์ด ๋ค๋ฅด๋ฉด ๋ง์ถ ํ ๋น๊ตํฉ๋๋ค
๋๋ฑ ๋น๊ต ์ฐ์ฐ์ [ ==, !=, ===, !== ]
3์ค๋ ๊ธธ๋ค๋ฉด 1์ค ์์ฝ
๋๋ฑ ๋น๊ต ์ฐ์ฐ์ [ ==, !=, ===, !== ]
๋งค๋ฒ ์ฑ ์์ ์ฐ์ง ๋ง๋ผ๊ณ ํ๋๋ฐ ์ ๊ทธ๋ฐ์ง ๋ด ์๋ค
๋๋ฑ ๋น๊ต ์ฐ์ฐ์ [ ==, !=, ===, !== ]
== ์ฐ์ฐ์์ === ์ฐ์ฐ์๊ฐ ์ด๋ป๊ฒ ๋์ํ๋์ง
๋ญ๊ฐ ์ผ๋ง๋ ๋ฌ๋ผ์ ์ฐ์ง ๋ง๋ผ๋ ๊ฑด์ง ๋๋ฌด ๊ถ๊ธํด ์ก์ต๋๋ค
๊ทธ๋์ ์ค๋๋ง์ ์์ฒญ๋ ์ผํฌํธ ๊น๊ธฐ ใ ใ ใ
์ผํฌํธ์ ๊น...์์ ์์๊น์?
๋๋ฑ ๋น๊ต ์ฐ์ฐ์ [ ==, !=, ===, !== ]
์ ๊ฐ ๊ฐ์ ธ์จ ์ผํฌํธ ์ ๋ฌผ์ ๋ ๊ฐ ์ ๋๋ค
๐ v8/tags/4.3.18/src/runtime.js
โ V8 ์์ง ์์ค์ฝ๋
๐ ECMAScript Equality Operators
โ ECMAScript ๋ช ์ธ
Abstract Equality Comparison [ == ]
The comparison x == y, where x and y are values, produces true or false. Such a comparison is performed as follows:
1. If Type(x) is the same as Type(y), then
a. Return the result of performing Strict Equality Comparison x === y.
2. If x is null and y is undefined, return true.
3. If x is undefined and y is null, return true.
4. If Type(x) is Number and Type(y) is String, return the result of the comparison x == ! ToNumber(y).
5. If Type(x) is String and Type(y) is Number, return the result of the comparison ! ToNumber(x) == y.
6. If Type(x) is Boolean, return the result of the comparison ! ToNumber(x) == y.
7. If Type(y) is Boolean, return the result of the comparison x == ! ToNumber(y).
8. If Type(x) is either String, Number, or Symbol and Type(y) is Object, return the result of the comparison x == ToPrimitive(y).
9. If Type(x) is Object and Type(y) is either String, Number, or Symbol, return the result of the comparison ToPrimitive(x) == y.
10. Return false.
Abstract Equality Comparison [ == ]
Strict Equality Comparison [ === ]
1. If Type(x) is different from Type(y), return false.
2. If Type(x) is Number, then
a. If x is NaN, return false.
b. If y is NaN, return false.
c. If x is the same Number value as y, return true.
d. If x is +0 and y is -0, return true.
e. If x is -0 and y is +0, return true.
f. Return false.
3. Return SameValueNonNumber(x, y).
Number ๋น๊ต๊ฐ ์๋ ๊ฒฝ์ฐ์๋ ์ด ํจ์๋ฅผ ์ฐ๋๋ผ๊ตฌ์! ๋๋ฐ ์ ๊ธฐ์ฐ
1. x, y ๋ ๊ฐ์ ํ์ ์ด๋ผ๊ณ ๊ฐ์ ํ๋ค
2. null, undefined, Symbol, String, Boolean, Object ๊ฐ ๋น๊ต๋ฅผ ํ์ฌ true || false ๋ฅผ ๋ฐํ
Strict Equality Comparison [ === ]
โ return ๊น์ง min(1) ~ max(3) ๋จ๊ณ
Abstract Equality Comparison [ === ]
โ return ๊น์ง min(1) ~ max(10) ๋จ๊ณ
์ฌ์ง์ด ๋ด๋ถ์ ์ผ๋ก Strict Equality Comparison ํธ์ถ
Equality Comparison [ ==, === ]
๋ง์ฝ == ์ฐ์ฐ์๋ฅผ ์ฐ๊ณ ์ถ์ผ์๋ฉด, ๋ช ๊ฐ์ง ์์ธ ์ผ์ด์ค๋ฅผ ์ธ์ฐ์๋ฉด ๋ฉ๋๋ค!
1. undefined == null
2. string - number ๊ฐ ๋น๊ต๋ ๋ฌธ์์ด์ ์ซ์๋ก ๋ฐ๊ฟ์ ๋น๊ต
3. bool - number (or string) ๋น๊ต๋ bool ์ ์ซ์๋ก ๋ฐ๊พผ ๋ค ๋น๊ต
1. bool ๊ณผ string ๋น๊ต๋ ๋ ๋ค ์ซ์๋ก ๋ณํํ์ง๋ง
2. ๋น์ด ์์ง ์์ ๋ฌธ์์ด์ด ๋ชจ๋ true ๋ ์๋๋ค ('0' == true)
4. object - number (or string) ๋น๊ต๋ ๊ฐ์ฒด๋ฅผ ์์ ๊ฐ์ผ๋ก ๋ฐ๊พผ ๋ค ๋น๊ต
5. ๊ทธ ์ธ๋ ๋ชจ๋ false
์! ์ด๋ฐ๊ฒ๋ ์ธ์ ๋์ ์ผ ํฉ๋๋ค ํํ ํธํธ
์ด๊ฑธ ์ธ์ฐ๋๋ ๊ทธ๋ฅ === ์ ์์๋ค...
Equality Comparison [ ==, === ]
๋ญ๊ฐ ์ ์ฉํด ๋ณด์ด๋ ํจ์ ๋ค์ ์์ง ๋ง์ธ์!
๋น๊ต ์ฐ์ฐ์ [ >, <, >=, <= ]
๋น๊ต ์ฐ์ฐ์๋ ๋ค์๊ณผ ๊ฐ์ ์์๋ฅผ ๊ฑฐ์นฉ๋๋ค
1. ํผ ์ฐ์ฐ์ ๋ชจ๋๋ฅผ ์์ ๊ฐ์ผ๋ก ๋ฐ๊ฟ๋๋ค (ToPrimitive)
2. ๋ ํผ ์ฐ์ฐ์๊ฐ ๋ชจ๋ ๋ฌธ์์ด์ด๋ฉด ํด๋น ๋ฌธ์์ด์ ์๋ฐ์คํฌ๋ฆฝํธ ๋ฌธ์์ธ 16๋นํธ ์ฝ๋ ๋จ์๋ฅผ ์ฌ์ ์์๋ก ๋น๊ตํฉ๋๋ค
3. ๊ทธ๋ ์ง ์์ผ๋ฉด ๋ ํผ์ฐ์ฐ์๋ฅผ ๋ชจ๋ ์ซ์๋ก ๋ฐ๊ฟ ๋น๊ตํฉ๋๋ค
์์ค ์ฝ๋ ์ ๊น ๋ณผ๊น์?
๋น๊ต ์ฐ์ฐ์ [ >, <, >=, <= ]
์ฐ์ ์ฐ์ฐ์ [ +, -, *, /, % ]
์ฐ์ ์ฐ์ฐ์์๋ ๋ช๊ฐ์ง ์์ธ๊ฐ ์์ต๋๋ค (์์ธ์ ์ธ์ด ์๋ฐ์คํฌ๋ฆฝํธ ๐ญ)
1. + ๋ฅผ ์ ์ธํ ์ฐ์ฐ์์ ์ซ์ OP [์ซ์๊ฐ ์๋ ๊ฐ] ์ ๊ฒฐ๊ณผ๋ NaN ์ด๋ค
โ ์์ฒญ ํํ ์ค๋ฅ
2. 0์ผ๋ก ๋๋์ด๋ ์ค๋ฅ๊ฐ ์๋ค (Infinity)
3. + ์ฐ์ฐ์ ์กฐ๊ฑด์ด ๋ค์ ์๊ณ ๋ฆฌ์ฆ์ ๋ฐ๋ฆ ๋๋ค
1. ๋ ํผ์ฐ์ฐ์๋ฅผ ๋ชจ๋ ์์๊ฐ์ผ๋ก ๋ฐ๊ฟ๋๋ค (ToPrimitive)
2. ์์๊ฐ ์ค ํ๋๋ผ๋ ๋ฌธ์์ด์ด๋ฉด ๋ค๋ฅธ ํ๋๋ ๋ฌธ์์ด๋ก ๋ณํํ์ฌ ํฉ์น ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํฉ๋๋ค
3. ๊ทธ๋ ์ง ์์ผ๋ฉด ๋ ํผ์ฐ์ฐ์ ๋ชจ๋ ์ซ์๋ก ๋ฐํํ๊ณ ๋ํ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํฉ๋๋ค
์ฐ์ ์ฐ์ฐ์ [ +, -, *, /, % ]
TMI: 0์ผ๋ก ๋๋๋ฉด ์๋๋ ์ด์
1. ๋๋์ ์ ํผ์ฐ์ฐ์์ ์ ์์ ๋บ์ ์ฐ์ฐ
2. ์ ์๋ 0์ด๋ฏ๋ก ์์ํ ๋นผ์ผ ํจ
3. ์ค๋ฅ
๋ค์์ ํ ๊ฑฐ: ์ฐ์ ์ฐ์ฐ์ (์ถ๊ฐ), ๋ถ๋ฆฌ์ธ ์ฐ์ฐ์, ๋นํธ ์ฐ์ฐ์, ํน์ ์ฐ์ฐ์, void, typeof, instanceof, ๊ฐ์ฒด ์ฐ์ฐ์ (new, delete, in)