In JavaScript, Data refers to the values that are stored and manipulated within a program. It represents the information that is processed, stored, and used to perform various operations. Data in JavaScript can have different types, such as numbers, strings, booleans, objects, arrays, null, and undefined.
Javascript Data
examples of data definition in JavaScript along with explanations :
Number
let age = 25;
In this example, the variable age is assigned the value 25, which represents a numeric data type.
String
let name = "John Doe";
The variable name is assigned the string value "John Doe" , which represents textual data.
Boolean
let isActive = true;
The variable isActive is assigned the boolean value true, which represents a logical state.
Null
let value = null;
The variable value is assigned the value null, indicating the intentional absence of an object value.
Undefined
let data;
The variable data is declared without an initial value, resulting in an undefined value.
Object
let person = {
name: "John",
age: 25,
isActive: true
};
The variable person is assigned an object containing key-value pairs representing properties of a person.
Function
function sayHello() {
console.log("Hello!");
}
The sayHello function represents a reusable block of code that outputs "Hello!" when called.
Array
let numbers = [1, 2, 3, 4, 5];
let fruits = ["apple", "banana", "orange"];
The variable numbers is assigned an array of numeric values, while fruits contains an array of string values.