Using Strict Equality

If you read the specs on JavaScript, you will soon come across the fact that "JavaScript is a loosely typed language with automatic coercion"! OK, great, but what does that gobbledygook mean? What it actually means is that, despite the fact that values with different data types look the same, in fact, they are not equal..

There are, in fact, three sets of data types available in JavaScript:

The primary (primitive) data types are:

  • String
  • Number
  • Boolean

The composite (reference) data types are:

  • Object
  • Array

The special data types are:

  • Null
  • Undefined

The expressions in the following example all evaluate to true.

"100" == 100; //text and number
false == 0; //boolean and number

If you want to check that both the type and value are the same, you can use the strict equality operator, ===.

Using this operator, the following both evaluate to false:

"100" === 100;
false === 0;

Kathie Kingsley-Hughes
Last updated: May 4th 2004
Print This Page   |   Email me when this page changes    |  Search This Site System Scanner does the work for you!

udes/a_global/"); ?>

Contact Us