JavaScript has several data types that can be used to store different kinds of information. These data types include:
Number :
JavaScript uses the number data type to store numeric values. This can include integers (whole numbers) as well as floating-point numbers (numbers with decimal points).
let x = 5;
let y = 3.14;
String :
JavaScript uses the string data type to store sequences of characters. Strings are enclosed in single or double quotes.
let name = "John Doe";
let message = 'Hello, world!';
Boolean :
JavaScript uses the boolean data type to store true or false values.
let isValid = true;
let isComplete = false;
Array :
JavaScript uses the array data type to store multiple values in a single variable. Arrays are enclosed in square brackets and each element is separated by a comma.
let colors = ["red", "green", "blue"];
let numbers = [1, 2, 3, 4, 5];
Object :
JavaScript uses the object data type to store collections of key-value pairs. Objects are enclosed in curly braces and each key-value pair is separated by a colon.
let person = {
name: "John Doe",
age: 30,
isStudent: false
};
Function :
JavaScript uses the function data type to store blocks of code that can be called multiple times. Functions are declared using the function
keyword.
function greet() {
console.log("Hello, world!");
}
Undefined :
JavaScript uses the undefined data type to indicate that a variable has been declared but has not been assigned a value.
let x;
console.log(x); // undefined
Null :
JavaScript uses the null data type to indicate that a variable has no value.
let x = null;
console.log(x); // null
These are the main data types in JavaScript. By using these data types, you can store and manipulate different kinds of information in your JavaScript code. It's important to note that JavaScript is a loosely typed language, which means that the data type of a variable can change at runtime.
JOIN WHATSAPP COMMUNITY FOR MORE SUCH AWESOME CONTENT :
<aside> 💡 CLICK HERE TO JOIN
</aside>
Join Instagram Community ( 80k+) : @webdevarmy & @cssdevarmy
Youtube : @webdevarmy