JavaScript Data Type with Example
JavaScript DataTypes
Data types is basically used to specify what kind of data can be stored and manipulated within a program.
It means Data type indicates characteristics of data. It tells the compiler whether the data value is numeric, alphabetic, date etc., so that it can perform the appropriate operation.
There are following Data Type:
JS Number Data Type
JavaScript has only one Number (numeric) data types. Number data type can store normal integer, floating-point values.
The number data type is used to represent positive or negative numbers with or without decimal place
675,89.654
Example:
Result:
12 30.5 6250000 0.00000925
JS String Data Type
String is a primitive data type in JavaScript. A string is textual content. It must be enclosed in single or double quotation marks.
Example:
Result:
Demo: JavaScript String Welcome to aimtocode Keep Learning
JS Boolean Data Type
JavaScript Boolean dat type returns values either in true or false, and it is use to perform logically operator to determine condition/expression is true
Example:
Result:
Demo: JavaScript Boolean false false false false false true true
JS Null Data Type
JavaScript Null specifies variable is declare but values of this variable is empty
Example:
Result:
null Wel-come to aimtocode! null
JS Undefined Data Type
This can only have one value-the special value undefined. If a variable has been declared, but has not been assigned a value, has the value undefined
Example:
Result:
undefined Wel-Come to aimtocode!
JS Object Data Type
The object is a complex data type that allows us to store collections of data.
Undefined is also a primitive value in JavaScript. A variable or an object has an undefined value when no value is assigned before using it
JavaScript objects are written with curly braces {}.Object properties are written as name:value pairs, separated by commas.
Example:
Result:
JavaScript Objects Rahul is 22 years old.