JavaScript typeof operator

typeof vs ==

It sounds strange but most of the web developers still use == operator to check the ‘undefined’ value of a JavaScript variable. Don’t know why but however there’s typeof operator and I strongly recommend it for that purpose.

It simply should be:

typeof variable == ‘undefined’

Related posts:

  1. javascript: what is typeof typeof
  2. Does JavaScript undefined Equals undefined?
  3. OOP JavaScript: Accessing Public Methods in Private Methods
This entry was posted in javascript, micro tutorial, web development and tagged . Bookmark the permalink.

One Response to JavaScript typeof operator

  1. Bill says:

    Why not just use the variable. For example,
    if( variable ) {
    alert( “The value is defined” );
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">