JavaScript Data Types

JavaScript has six different types of value. There are five primitive data types:

■ string

■ number

■ Boolean

■ undefined

■ null

Any value that isn’t one of the primitive data types listed is an object. I’ll discuss each primitive value over the next few pages.

JavaScript has a special operator called typeof for finding out the type of a value.

Here are some examples of the different value types:


typeof "hello"
<< "string"
typeof 10
<< "number"
typeof true
<< "boolean"

typeof { ninja: "turtle" }
<< "object"
 

Operators

An operator applies an operation to a value, which is known as the operand. A unary operator only requires one operand; for example:
typeof "hello" 

The operator is typeof and the string "hello" is the operand.

binary operator requires two operands; for instance:
3 + 5 

The operator is and the numbers and are the operands. There is also a ternary operator that requires three operands, which is covered in the next chapter.

0 Response to "JavaScript Data Types"

Post a Comment