We can write numbers in two types i.e. integer and float. Numbers can be written with or without decimals. They represent numeric values. The simplest type of number is an integer with no fractional component. Another type is floating point number which is assumed to have decimal point.
document.write ("Result :");
For string type, a value must be assigned in within single or double quotes. It is sequence of characters within given character set. Normally it is used to represent text. If we create a string with no value in it, then it is called as empty string.
var a="hello world";
document.write("result is true");
Composite Data Types
- Object: An object is collection of values, which is referred to as properties of objects and functions associated with the object are referred to as methods of that object. The properties and methods are denoted with dot notation which starts with object name and ends with property name. For instance: emp.emp_name.
Special Data Types
alert(myTest);//shows null value
A variable declared without a value can be called as undefined. The undefined value is assigned to a variable to which value has never assigned to it.
document.write ("comparing a to undefined ");
Variables are declared by using “var” keyword.
var a=5; –> Integer type variable
var str="javabeat"; –> String type variable
var b=true; –>Boolean type variable
- Global variables: A variable can be declared outside a function is called global variable.
- Local variables: A variable which is defined within function definition is called local variable. It is created and destroyed every time when function is executed and it cannot be accessed by outside any of the function.
var myTest; //global declaration
var myTest1="hello world!!" ; //local declaration
- We should not use reserved keyword as variable name.