Content:
JavaScript is a dynamically typed language, meaning variables can hold values of any type without explicit type declaration. JavaScript data types are divided into two categories: primitive and non-primitive (reference) types.
Primitive Data Types:
-
number: Represents numeric values, including integers and floating-point numbers.let age = 25; let price = 99.99; -
string: Represents textual data enclosed in single or double quotes.let name = 'Alice'; -
boolean: Represents a logical value:trueorfalse.let isActive = true; -
undefined: Represents a variable that has been declared but not assigned a value.let x; console.log(x); // undefined -
null: Represents an intentional absence of any object value.let y = null; -
bigint: Represents integers larger than thenumbertype can handle.let bigNumber = 1234567890123456789012345678901234567890n; -
symbol: Represents a unique and immutable value, often used as object property keys.let id = Symbol('id');
Non-Primitive Data Types:
-
object: Represents a collection of key-value pairs. This includes arrays, functions, and objects.let person = { name: 'Alice', age: 25 }; let colors = ['red', 'green', 'blue']; -
function: Functions are objects that can be called to perform tasks.function greet() { console.log('Hello!'); }
Type Checking:
- Use the
typeofoperator to check the type of a value.console.log(typeof 42); // "number" console.log(typeof 'Hello'); // "string" console.log(typeof {}); // "object" console.log(typeof function() {}); // "function"
Connections:
Connections:
Sources: