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.

Related Posts :

  • BooleansThere are only two Boolean values: true and false. They are named after George Boole, an Englis… Read More...
  • NullNull means "no value". It can be thought of as a placeholder that JavaScript uses to say "there… Read More...
  • Bitwise OperatorsBitwise operators work with operands that are 32-bit integers. These are numbers written in bin… Read More...
  • Logical OperatorsA logical operator can be used with any primitive value or object. The results are based on whe… Read More...
  • ComparisonWe often need to compare values when we are programming. JavaScript has several ways to compare… Read More...

0 Response to "JavaScript Data Types"

Post a Comment