errores de captura de javascript, nulo
Frecuentes
Visto 60 veces
-3
When using the following syntax, would the output in console be out
?
I am making sure that I'm catching errors in callbacks and responding properly.
var err = null;
if (err) {
console.log ("in");
} else {
console.log ("out");
}
3 Respuestas
2
If your value is one of the following:
- 0
- nulo
- ""
- false
- indefinido
- Yaya
the object is set to false. For any other value it is set to true.
Respondido el 28 de enero de 14 a las 18:01
2
Using either your browser's JavaScript console or a site like http://repl.it/ can be really helpful to test logical expressions. One thing you can always do if you're not sure about the truthiness of an expression (doesn't matter as much for a simple case like this, but can be especially helpful when debugging with watch expressions or conditional breakpoints) is cast it to boolean (true/false) by using the !
operator twice. For example:
!!null === false // true
!!0 === false // true
!![] === true // true
Respondido el 28 de enero de 14 a las 18:01
1
The answer is Yes. But you can test it yourself by running in the browser.
Respondido el 28 de enero de 14 a las 18:01
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas javascript or haz tu propia pregunta.
yes, null is "falsey" - jalynn2
@jalynn2 perfect :) thanks! - Cmag
null
,undefined
,false
,0
etc.. will printout
- DontVoteMeDownWhy haven't you simply tried it out? - Bergi
This question appears to be off-topic because it is something that could have easily been answered in 2 seconds by the poster trying it out himself. - user663031