Javascript Basic Data Types
We can need to define the variable in any programming language. As a beginner, we don’t know about which type of data we define with a variable. So, at first, we need to know about the data type. Today we discuss javascript data types. Basically, Javascript has two types of data types:
- Primitive Data Types
- Non-Primitive/Reference Data Types
typeof Operator:
It helps us to check which type of data we are defined. Check an example below:
var name = 'Nabed';
console.log(typeof name);Output is: string
Our result is the string because we declare a string value. So, Let’s discuss javascript data.
Primitive Data Types:
- Number
- String
- Boolean
- Null
- Undefined
Number Data Type:
When we declare a variable with a numeric value. it’s called number data type. we can also use the floating number.
var age = 24;
var price = 49.99;
String Data Type:
A string data type one or more character within the quotation. when we declare string we need to use double quotation(“ ”) or single quotation (‘ ’).
var name = 'Nabed Khan';
Boolean Data Type:
Boolean data type provides us two values. true either false.
var value = true;
var value2 = false;console.log(typeof value);
console.log(typeof value2);Output is:
boolean
boolean
Null Data Type:
Null data type represented by empty, nothing, or unknown value. we need to write it in small letter.
var value = null;
Undefined Data Type:
The undefined mean value isn’t defined. Most of the time we didn’t assign a value with a variable. It’s called undefined value
var value
console.log(value);Output is: undefined
Non-Primitive/Reference Data Types:
- Object
Object Data Type:
The object data type used for the complex data structure. there are have a collection of properties and methods.
var person ={
name: 'Alex Smith',
age: 20,
profession: 'student',
address: 'New York, USA'
}