Numbers

There are different kinds of numbers in Javascript.

Integers: whole number - positive, negative, and 0
33
-1000
0

Floating-point number have a fractional part
3.0
0.0001
-99.003



Strictly speaking numbers aren't objects but javascript allows you to treat it like an object so you can do things like this
 var num = 123;
 num.toString();   // returns string "123"

 (123).toString(); // returns string "123"

Notes

Boolean

There is a special data type called boolean. It can have only two values, true or false. You can use it as 1 (true) or 0 (false) too.

var success = false;  // note that the value false is not in quotes.

var answer = confirm("is this okay?"); // this will return a boolean
alert(answer);           // will print out true or false
if(answer){
    alert("you ARE ok");
}

if(!answer){             // ! -- is the negation operator. It turns it into the opposite value
    alert("you are NOT ok");
}

Notes

The Number Object

Number object allows you to analyze and manipulate numbers.

//NaN: Not a Number
Number.isNaN(3);      // returns false
Number.isNaN("boo");  // returns true



Number.isInteger(123);   // returns true
Number.isInteger(123.4); // returns false


//parseFloat() and parseInt() force conversion of a string into a number
Number.parseFloat("21.4");  // returns 21.4

// if the first character in the string is a number, 
// it parses the string until it reaches the end of that number
Number.parseFloat("76 trombones") // returns 76.0 
Number.parseFloat("The magnificient 7"); // returns NaN


Number.parseInt(18.95);   // returns 18
Number.parseInt("12px");  // returns 12
Number.parseInt("1110");  // returns 1110
Number.parseInt("Hello"); // returns NaN 



// Swiss Army Knife for getting numerical values from other data types
Number(true);     // 1 
Number(false);    // 0
Number("123");    // 123
Number("horse");  // NaN
Notes