모던 자바스크립트 deep dive
study with : zigum man
var x = "1";
console.log(+x) // 1
console.log(x) // "1"
x = true;
console.log(+x) // 1
x ="hello";
console.log(+x) // NaN
'1' + 2; // '12'
1 + true; // 2
NaN===NaN // false
object.is(NaN,NaN) // true
var result = rank > 55 ? : 'good':'fail';
2**2; // 4
Math.pow(2,2); // 4
(-2)**3 // -8
x**=3;
JavaScript provides both strict(===, !==) and type-converting(==, !=) equality comparison.
자바스크립트는 엄격하게 비교하는 일치비교(===,!==)와 값만 보는 동등비교(==,!=) 두가지를 제공한다.
The strict operators take type of variable in consideration, while non-strict operators make type correction/conversion based upon values of variables.
엄격한 연산자는 변수의 타입까지 고려하고, 엄격하지 않은 연산자는 변수의 값을 기초로 타입을 수정/변환 하여 비교한다.
The strict operators follow the below conditions for different types,
엄격한 연산자는 다른 타입을 아래의 조건에 따라 처리한다.
Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.
두 문자열은 같은 문자, 길이, 각 문자의 위치를 엄격하게 비교한다.
Two numbers are strictly equal when they are numerically equal. i.e, Having the same number value.
두 숫자는 수학적으로 같은지 엄격하게 비교한다.(같은 값의 숫자인지)
There are two special cases in this,
NaN is not equal to anything, including NaN.
두개의 특별한 규칙이 있다. NaN은 자신을 포함하여 어떤것과도 같지 않다.
Positive and negative zeros are equal to one another.
-0과 +0은 같다.
Two Boolean operands are strictly equal if both are true or both are false.
불리안 형식은 둘다 true이거나 둘다 false인지 엄격하게 비교한다.
Two objects are strictly equal if they refer to the same Object.
두 객체는 같은 객체를 참조하는지 엄격하게 확인한다.
Null and Undefined types are not equal with ===, but equal with ==. i.e, null===undefined --> false but null==undefined --> true
null과 undefined의 타입은 == 에서는 같고 ===에서는 같지 않다.
Some of the example which covers the above cases,
0 == false // true
0 === false // false
1 == "1" // true
1 === "1" // false
null == undefined // true
null === undefined // false
'0' == false // true
'0' === false // false
[]==[] or []===[] //false, refer different objects in memory
{}=={} or {}==={} //false, refer different objects in memory