Primitive data types are predefined by the language and named by a keyword .This chapter will cover three primitive data types separately and one more trivial data type Null or Undefined.
Number Data Type:
Following example will show you the simple manipulation of number data types.
Figure 1: Above figure is output of number data types and a simple mathematical calculation over the values stored by variable.
Boolean Data Type:
Variable declaration is done like this
Figure 2: Above figure is output of Boolean data type script in which value2 is printing its true comparison value.
String Data Type:
A string is used to represent normally text that is sequence of valid characters within a given character group. It always defined by enclosing single or double quotes. Sometimes it happens that you want to put some characters in a string may not exist on the keyboard, or may be special characters that can't appear as themselves in a string. For that case you need to use an escape sequence to represent the character. An escape sequence is a character or numeric value representing a character that is followed by a backslash ( \ ) to indicate that it is a special character.
Figure 3: Above figure is output of string data type in which stored value in variable are printed on output screen.
Null or Undefined Data Types:
Java script has two more literals; null and undefined, that is considered to be objects. Value null means that it does not have any valid object, string, number or Boolean value. Basically we can say that It is the value of no value. Normally you assign the value null to something when you want it to have a valid but non-existent value.
An undefined variable is one that has been named, but does not have a value assigned to it. In case of undefined, first of all we should know that undefined is not keyword. It is a predefined global variable, but it is treated like any other variable. Be careful not to overwrite it. The variable undefined is used to store the value of an undefined variable.
var Var1=null; var Var2=null;