JavaScript provides different data types to hold different types of values. There are two types of data types in JavaScript.
The typeof operator is used to get the data type (returns a string) of its operand. The operand can be either a literal or a data structure such as a variable, a function , or an object.
- Primitive Data Type
- Reference Data Type (Non Primitive)
1. Primitive Data Type
- String
- Number
- Boolean
- Null
- Undefined
- Symbol
// Primitive data type
//String
let myName = 'Pradeep';
console.log( 'My String is '+ myName);
console.log( 'My DataType is '+ (typeOf myName));
// Output: My String is Pradeep
// Output: My DataType is string
// Numbers
let marks = 45;
console.log( 'My marks is '+ marks);
console.log( 'My DataType is '+ (typeof marks));
// Output: My marks is 45
// Output: My DataType is Number
// Boolean
let isDriver = true;
console.log('DataType is ' + (typeof isDriver));
// Output: My DataType is Boolean
// Null
let nulVar = null;
console.log('DataType is ' + (typeof nulVar));
// Output: My DataType is Object but it's primitive data type
// Undefined
let unDef = undefined;
console.log('DataType is ' + (typeof unDef));
// Output: My DataType is Undefined
2. Reference data type
- Array
- Object Literal
- Function
- Dates
// Refrence data type
// Arrays
myarr = [1, 2, 3, 4];
console.log('DataType is ' + (typeof myarr));
// Object Literals
let stMarks{
pradeep:52,
Kevu:65,
Ashwat: 63
}
console.log(stMarks)
console.log( 'My DataType is '+ (typeof stMarks));
// Function
function test(){
}
console.log(typeof test)
// date
let date = new Date();
console.log(typeof date)
Comments
Post a Comment