mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00: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:
parent
d4d471ef50
commit
c3a66e60a6
@ -507,6 +507,10 @@ myNumber === myNumberObj; // = false
|
||||
if (0){
|
||||
// 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
|
||||
// you can actually add functionality to a string, for instance.
|
||||
|
Loading…
Reference in New Issue
Block a user