JavaScript has only one type of numbers – 64-bit float point. It's the same as Java's double . Unlike most other programming languages, there is no separate integer type, so 1 and 1.0 are the same value. In this chapter, we'll learn how to create numbers and perform operations on them (like additions and subtractions). Creating a number is easy, it can be done just like for any other variable type using the var keyword. Numbers can be created from a constant value: // This is a float: var a = 1.2; // This is an integer: var b = 10; Or from the value of another variable: var a = 2; var b = a;
Programmers frequently need to determine the equality of variables in relation to other variables. This is done using an equality operator.+ The most basic equality operator is the == operator. This operator does everything it can to determine if two variables are equal, even if they are not of the same type. For example, assume: var foo = 42 ; var bar = 42 ; var baz = "42" ; var qux = "life" ; foo == bar will evaluate to true and baz == qux will evaluate to false, as one would expect. However, foo == baz will also evaluate to true despite foo and baz being different types. Behind the scenes the == equality operator attempts to force its operands to the same type before determining their equality. This is in contrast to the === equality operator. The === equality operator determines that two variables are equal if they are of the same type and have the same value. With the same assumptions as before, this means that foo === bar will still evaluate to t...