JavaScript data types with example - AsgarTech

 JavaScript data types with example - AsgarTech 


 

JavaScript data types, including:

Number: Used for numeric values, both integer and floating-point.
 Example: const num = 42;

String: Used for textual data. 
Example: const str = "Hello World!";

Boolean: Used for logical values, which can be either true or false. 
Example: const isTrue = true;

Null: Used to represent the intentional absence of any object value. 
Example: const noValue = null;

Undefined: Used to represent the absence of a value, or an uninitialized variable.
 Example: let myVar; // myVar is undefined

Object: Used for complex data structures, consisting of key-value pairs. Example: 

const person = {
  name: "John Doe",
  age: 30,
  address: {
    street: "123 Main St",
    city: "Anytown",
    state: "CA"
  }
};

Array: Used for ordered collections of data. 
Example: const myArray = [1, 2, 3, 4, 5];

Symbol: Used to create unique identifiers for object properties.
 Example:

const sym = Symbol("description");
const obj = {
  [sym]: "value"
};



No comments: