home

Javascript Primitive Data types

Javascript has the following data types:-

1. String – anything inside the double quotes like “abc”, “one”, “3000”, “1 two three”. 2. Number - this includes integers and floating points like 2, 200, 2.22. 3. Boolean – Booleans can be true or false. 4. Array – most useful, an array can store some bunch of content. 5. Object – in javascript anything is an object. 6. Undefined – The undefined properties indicates because that a variable has not assigned a value. 7. Null – Another special data type that have only one value, it means value is nothing.

Javascript Numbers

Javascript number has only one type of number, that will be normal number and number can be also floating (decimals).

var num = 12.003;
 Typeof  num;
“number”

Numbers always integers. If you assign 10 to variable and then use the type of operator, it will return the string number. Also you will see that we don’t have variable, we don’t need the var statement.

num = 10;
Typeof num;
“number”;

Javascript Octal Number

When 0 leading the value that’s called octal number. For example 0002397. This kind of things mostly we can see in the css style (#0000ff) when we are applying styles for any component in the javascript.

var num = 0002397;

Javascript hexadecimal Number

Var x = 0x0ff;

Javascript Booleans

Javascript Booleans represent only two values, the values true or false without quotes.

Javascript Booleans function

Here we have example of Boolean function, value of 8 greater than 7, so the answer will be true. The reason is 8 bigger than the 7.

Boolean (8 > 7) value will be true

Comparison and conditions

== Equality, 100 == 100 (its return the truth when the both values are equal).
=== equality and type, 100===100 (this will return the truth, this will check equality and comparison).
> greater then, 100>90 (return truth if right values is greater than the left value).
< less than, 90<100 (return truth if left values is greater than the right value).
!= not equal 100!=100(This will return the truth if the values is not equal to each other).

Javascript Undefined

The undefined properties indicates because that a variable has not assigned a value.

var a;
if (a === undefined) {
    txt = "a is undefined";
} else {
    txt = "a is defined";
}
result will be a is undefined.

Javascript Null

Another special data type that have only one value, it means value is nothing.

 var car = null; 

Value is null, but type is still an object