June 1, 2023
1- primitive datatype
// String
const name1 = "John Deo";
// Defined variable name1 and initialized value "John Dev".
console.log(name1);
// ("run from",name1 )
// Number
const num1 = 7;
// Defined variable num1 and initialized 7 in num1
const num2 = 3.1415;
// Defined variable num2 and initialized 3.1415 in num2
const num3 = 89e5;
// Defined variable num3 and initialized 89e5 in num3
console.log(num1, num2, num3);
// ("run from", num1, num2, num3)
// Boolean
const data1 = true;
// Defined data1 variable and initialized boolean value true
const data2 = false;
//Defined data2 variable and initialized boolean value false
console.log(data1, data2);
// ("run from", data1, data2)
// Undefined
let undefine;
// Defined undefine variable and left as is uninitialzed
// without any value
console.log(undefine);
// ("run from", undefine)
// Null
const n = null;
// Defined n variable (special keyword denoting a null value)
console.log(n);
// ("run from", n)
// Symbol
let id = Symbol("nehal");
// Symbols are unique and cannot be changed. In JavaScript
// ES6 it was introduced as a new primitive data type.
console.log(id);
Output
John Deo
7 3.1415 8900000
true false
undefined
null
Symbol(nehal)
2- Object datatype
// Array
const animal = ["cat", "dog", "goat"];
// Defined animal variable and initialized 3 Array value
console.log(animal[1]);
// ("run from animal[1] than print is index value 2(dog)
// and array value(1));
// Object;
const student = {
// Defined student variable
Name: "Anil Kumar",
// Defined object name
class: 6,
// Defined object class
Roll: 45,
// Defined object Roll
};
console.log(student);
// ("run from", student than print all object value)
// Date
let now = Date();
// Defined now variable and initialized date and
// Define value any date month year
//alert=(now);
// ("run from", shows current date/time)
console.log(now);
Output
dog
{ Name: 'Anil Kumar', class: 6, Roll: 45 }
Thu Jun 15 2023 13:04:55 GMT+0530 (India Standard Time)
by : Nehal Akhtar
Quick Summary:
Data Types of JavaScript