errores de captura de javascript, nulo

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");

preguntado el 28 de enero de 14 a las 18:01

yes, null is "falsey" -

@jalynn2 perfect :) thanks! -

null, undefined, false, 0 etc.. will print out -

Why haven't you simply tried it out? -

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. -

3 Respuestas

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

Using either your browser's JavaScript console or a site like 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

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 or haz tu propia pregunta.