TIL 2018-08-09
오늘 배운 것 & 한 것
1. sports - beakjoon
- 1260
충격..
자바스크립트에서 []==false
는 true
이지만, if([]){console.log('wth?!')}
는 wth?!
를 출력한다!!
이유는, ==
는 coerce를 하나, if문과 같은 expression 자체에서는 다음과 같이 evaluation하기 때문이라고 한다.
from ref#1
Undefined -> false
Null -> false
Boolean -> The result equals the input argument (no conversion).
Number -> The result is false if the argument is +0, −0, or NaN; otherwise the result is true.
String -> The result is false if the argument is the empty String (its length is zero); otherwise the result is true.
Object -> true
즉 []
는 Object
로 평가되어 true
가 된다..
아무리 해도 틀린다. 도대체 왜일까. 분명 다 푼 것 같은데도 계속 틀린다..
- 1463
겨우 풀었다. 효율적으로 한 것 같은데도 9초씩이나 걸려서 어떻게 하지 했는데 알고보니 console.log
때문이었다. 알고보니 없애니까 1초도 안걸리는 코드였다.
node에서는 performance.now
대신 process.hrtime
이 있다.
Comments