mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-08 07:46:46 +02:00
[javascript/en] Re-add note about truthiness of wrapped primitives
Previous incarnations of this section had `Number(0)` instead of `new Number(0)`, which actually returns `0` due to the absence of the `new` keyword; this commit re-adds that section and better still, makes it actually correct!
This commit is contained in:
@@ -507,6 +507,10 @@ myNumber === myNumberObj; // = false
|
|||||||
if (0){
|
if (0){
|
||||||
// This code won't execute, because 0 is falsy.
|
// This code won't execute, because 0 is falsy.
|
||||||
}
|
}
|
||||||
|
if (new Number(0)){
|
||||||
|
// This code will execute, because wrapped numbers are objects, and objects
|
||||||
|
// are always truthy.
|
||||||
|
}
|
||||||
|
|
||||||
// However, the wrapper objects and the regular builtins share a prototype, so
|
// However, the wrapper objects and the regular builtins share a prototype, so
|
||||||
// you can actually add functionality to a string, for instance.
|
// you can actually add functionality to a string, for instance.
|
||||||
|
Reference in New Issue
Block a user