이상한 자바스크립트의 단점과 특징 😵
그래서 더 이상 고민하지 않고 바로 그 기묘함으로 뛰어 들어 갑시다.
!10 + !10
!10 + !10 ---> 0
The positive numbers in javascript are always true.
This Logical Not (!) represents the opposite. So, the opposite of true is false.
Hence, the false gets converted to 0.
So the answer is 0.
[] + []
[] + [] ---> ""
When using the addition operator, both the left and right operands are converted to primitives.
Converting an array to a primitive return its default value, which for objects with a valid toString() method is the result of calling object.toString()
For arrays this is the same as calling array.join()
Joining empty array results in an empty string.
Hence, the addition operator returns the concatenation of two empty strings, which is the empty string.
더 자세한 설명은 => Dr. Axel Rauschmayer의 이 문서를 참조하세요.
[2,4,6,8,10] + [12,14,16,18] = "2,4,6,8,1012,14,16,18"
[2,4,6,8,10] + [12,14,16,18] ---> "2,4,6,8,1012,14,16,18"
Arrays are converted into strings and then they are concatenated.
It follows the same rule as above.
난 === 난
NaN === NaN ---> false
Because it was the decision made by the IEEE-754 committee.
function isNaN didint exsist at that time.
자세한 설명은 => Stephen Canon의 StackOverflow 답변을 참조하세요.
NaN++
NaN++ ---> NaN
NaN literally means Not A Number.
Hence, NaN cannot be incremented.
정의되지 않은 + 참 | 정의되지 않음 + 거짓
undefined + true ---> NaN
undefined + false ---> NaN
True and False can be converted to numbers.
undefined cannot be converted to a number.
However , !!undefined + false => 0 , because (!!undefined means false).
!!undefined === false is true
Hence, If undefined is added with any boolean the result will always be NaN.
+0 === -0
+0 === -0 ---> true
Positive Zero and Negative Zeros are always equal in JavsScript.
[,,,].길이
[,,,].length ---> 3
This [,,,] simply means the array containing three empty slots.
The last comma is a trailing comma.
참 + 거짓
true + false ---> 1
Both the booleans are converted into their respective numerical representation and their values are added.
Number(true) ---> 1
Number(false) ---> 0
1 + 0 ---> 1
0.2 + 0.1 === 0.3
0.2 + 0.1 === 0.3 ---> false
Just think about representing 1/3 as a decimal value. It's impossible to do exactly! In the same way, 1/10 (decimal 0.1) cannot be represented exactly in binary as a "decimal" value; a repeating pattern after the decimal goes on forever and ever. The value is not exact, and therefore you can't do exact math with it using normal floating-point methods.
2,4 | 1,2,3,4,5 | "특이점", "특징"
2,4 ---> 4
1,2,3,4,5 ---> 5
"quirks","features" ---> "features"
The comma operator (,) evaluates each of its operands (from left to right) and returns the value of the last operand.
!!""
!!"" ---> false
Boolean representation of empty string("") is false.
Boolean("") ---> false
So, !!false ---> false
Inside Logical Not Operator(!) anything with a value is true and anything without a value is false.
+!![]
+!![] ---> 1
Boolean representation of empty array [] is true.
!!true is always true.
Plus operator converts into a numerical representation of that particular Boolean value.
Hence, +true is 1 .
참 == "참" ---> 거짓
true == "true" ---> false
Both of these values are converted to numbers .
Number(true) ---> 1
Number("true") ---> NaN
Hence, 1 == NaN is false
020 - 05
020 - 05 ---> 11
020 is treated as an octal number in JavaScript.
Its value in decimal is 16.
Hence, 16 - 5 is 11
"" - - ""
"" - - "" ---> 0
Empty string is converted into 0
It literally means (+0) - (-0)
Hence, (+0) - (-0) is zero.
널 + 420
null + 420 ---> 420
Numerical representation of null is always 0.
Number(null) ---> 0
Hence, 0 + 420 is 420
(널 - 0) + "0"
(null - 0) + "0" ---> "00"
Number(null) is 0
so, 0 - 0 is 0.
0 + "0" concatenates it and gives "00" as an answer.
Github에서 나를 팔로우하고
Reference
이 문제에 관하여(이상한 자바스크립트의 단점과 특징 😵), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/pramit_marattha/quirks-and-features-of-weird-javascript-25jk텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)