Professional Documents
Culture Documents
expression.
Undefined and null are equal in value but different in type.
Example 23
Example 28
typeof “” // Returns “string”
typeof undefined // undefined
typeof “Rithika” // Returns “string”
typeof null // object
typeof “Harini Kumar” // Returns “string”
null === undefined // false
typeof0 // Returns “number”
null == undefined // true
typeof81 // Returns “number”
typeof8.14 // Returns “number” Primitive Data
typeof(3+2) // Returns “number”
A primitive data value is a single simple data value with no
additional properties and methods. The typeof operator
Undefined
can return one of these primitive types.
In JavaScript, a variable without a value, has the value • string
undefined. The typeof is also undefined.
• number
Example 24
• boolean
var bike; // Value is undefined, type is
• undefined
undefined
Example 29
Note : Any variable can be emptied, by setting
the value to undefined. The type will also be typeof “Rajesh” // Returns “string”
undefined.
typeof 1.44 // Returns “number”
Empty Values typeof true // Returns “boolean”
An empty value has nothing to do with undefined. An typeof false // Returns “boolean”
empty string has both a legal value and a type. typeof a // if a has no value, it returns
Example 25 “undefined”
var bike = “”; // The value is “”, the typeof Complex Data
is “string”
The typeof operator can return one of two complex types:
Null
• function·
In JavaScript null is “nothing”. It is supposed to be
something that doesn’t exist. In JavaScript, the data type • object
of null is an object. You can empty an object by setting it
to null. The type of operator returns object for both objects, arrays
and null. It does not return object for functions.
Example 26
Example 30
var personName = {firstName:”Harini”,last Name;
”Kumar”, age:13, height:”155 cms”}; typeof {name, ‘Karthik’, age 27} // Returns “object”
personName = null; //Now value in null, but typeof [10, 20, 30, 40, 50] // Returns “object”
type is still an object (not “array”, see
You can also empty an object by setting it to undefined: note below)
typeof null // Returns “object”
Example 27
typeof function sampleFunc() { } // Returns “function”
var personName = {firstName:”Harini”, lastName:
”Kumar”, age:13, height:”155 cms”}; Note: The typeof operator returns “object” for
arrays because in JavaScript arrays are
personName = undefined; // Now both value and objects.
type is undefined.
IT & ITES : COPA (NSQF Level - 4) - Related Theory for Exercise 2.1.96A 9
The syntax to create a Constant is. But you can NOT reassign a constant object.
In the above syntax, “const” is the special keyword, const bike = {type:”Yamaha”, model:”R15", color:”blue”};
reserved to define a constant. As you can see, this syntax
looks a lot like a variable declaration but with the var bike = {type:”Tvs”, model:”Star city”, color:”black”};
keyword replaced with “const”. Most programmers use all
caps for the name of the constants to differentiate them // ERROR
from variables. Constant Arrays can Change
10
Sometimes JavaScript addition can results in unexpected 5^1 4 0101 ^ 0001 0100
results. 5 >> 1 2 0101 >> 1 0010
Example 8 5 >>> 1 2 0101 >>> 1 0010
IT & ITES : COPA (NSQF Level - 4) - Related Theory for Exercise 2.1.96B 11
12 IT & ITES : COPA (NSQF Level - 4) - Related Theory for Exercise 2.1.96B
*= /= %=
+= -= <<=
^= |=
IT & ITES : COPA (NSQF Level - 4) - Related Theory for Exercise 2.1.96B 13