Bitesize Bugs

Zero is ‘falsy’ in JavaScript

Numeric zero in JavaScript is a ‘falsy’ value.
If it is used in a conditional operator it will act as false.


var checkValue = function(value){
    var check = "";

       check = "it was "+value;
       check = "no value";

    return check;

// number; returns "no value"

// string; returns "it was 0"

Related reading:

Falsy values – extract from “JavaScript: The Good Parts”
Truthy and falsy in JavaScript


Filed under: Front-end, JavaScript, , , , , ,

One Response

  1. Alex says:

    Este mostenire de la C/C++.
    What, nu stiai? 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: