Data Types in JavaScript
Data Types in JavaScript
Example:
let person = { name: "Rahul", age: 25 }; // Object
let numbers = [1, 2, 3, 4, 5]; // Array
function greet() { console.log("Hello!"); } // Function
Example:
console.log(typeof "Hello"); // Output: string
console.log(typeof 42); // Output: number
console.log(typeof true); // Output: boolean
console.log(typeof null); // Output: object (Special case)
console.log(typeof undefined); // Output: undefined
console.log(typeof [1, 2, 3]); // Output: object (Arrays are objects)
console.log(typeof function(){}); // Output: function
note:
Use let and const instead of var.
JavaScript has 7 primitive data types and 3 non-primitive data types.
Use typeof to check data types.
JavaScript allows automatic (implicit) and manual (explicit) type conversion.