# JavaScript Data Types
● JavaScript Data Types.
JavaScript variables can hold may data types: numbers, strings, objects, array and more.
● The Concept of Data Types
In programming, Data Types are an important concept.
To be able to operate on variables, It is important to know something about the type.
Without data types, a computer can't safely solve this:
When adding a number and string, JavaScript will treat the number as string.
JavaScript evaluates expressions from left to right. Different sequences can produce different results.
In the variable x, JavaScript treats 16 and 4 as numbers, until it reaches "kevin".
In the variable y, Since the first operand is a string, all operands are treated as strings.
● JavaScript Booleans
Booleans can only have two values, True or False.
They are often used in conditional testing.
● JavaScript Arrays
JavaScript arrays are written with square brackets.
Array items are separated by commas.
The following code creates an array called arr, containing three items.
● JavaScript Objects
JavaScript objects are written with curly braces.
Object properties are written as name : value pairs, separated by commas.
● Primitive Data
A Primitive Data value is a single simple data value with no additional properties and methods. the typeof operator can return one of these primitive types.
- string
- number
- boolean
- null
- undefined
● Complex Data
The typeof operator can return one of two complex types:
- function
- object
● Undefined
In JavaScript, a variable without a value, has the value undefined. the typeof is same.
● Empty Values
An empty value has nothing to do with undefined. An empty string variable has both a value and a type.
● Null
In JavaScript null is nothing. It is supposed to be something that doesn't exist.
In JavaScript, the data type of null is an object.
No comments:
Post a Comment