Flashcards
Weird Behavior
Flashcards do conjunto (5)
- 1'b' + 'a' + + 'a' + 'a'; //'BaNaNa' ('b' + 'a' + + 'a' + 'a').toLowerCase() //bananaThe expression is evaluated as ‘ba’ + (+’a’), which converts +’a’ to not a number. Then the expression NaN+’a’ is evaluated as NaNa, and the final result is baNaNa
- 2Note: The !! operator converts an object to a boolean value. Null is a falsy value, but it’s not equal to false. !!null; //false null == false; //falseYou cannot convert null (and undefined) to any other value before comparing equality, so null == false is equal to false.
- 3An array and an empty array is always a truthy value, but it’s not equal to true. !![ ] //true [ ] == true //falseTrue is converted to 1 and [ ] is converted to 0 so[ ] ==true (0 == 1) is equal to false.
- 4[9, 8, 7] + [6, 5, 4] //"9,8,76,5,4"This result occurs because when you sum two collections, the “toString” is called in each array, so [9,8,7] is converted to “9,8,7” and [6,5,4] is convert to “6,5,4,” and then the concatenation happens.
- 5typeof(undefined) "undefined" typeof(null) "object"This behavior is a side effect of the first implementation of JavaScript. Values were represented as a type tag plus the value. However, null was served with a NULL pointer. The type tag for objects was 0. As a result, null is also interpreted as an object.
Informações
- Descrição
- Weird Behavior FlashCards sobre Weird Behavior, criado por milly larcen em 14-04-2020.
- Criado por
- milly larcen
- Visualizações
- 0
- Avaliação