JavaScript, as a versatile and widely-used programming language, supports various data types that are crucial for storing and manipulating different kinds of information. Understanding these data types is fundamental for any developer looking to write efficient and effective code.
In this article, we will delve into the different data types supported by JavaScript variables and provide practical examples to help you grasp their usage.
1. Numbers
In JavaScript, numbers are used to represent numeric values. They can be integers or floating-point numbers. Here’s an example:
let age = 30;
let price = 19.99;
2. Strings
Strings are sequences of characters enclosed in single or double quotes. They are used to represent text data. Here’s an example:
let name = 'Alice';
let message = "Hello, World!";
3. Booleans
Booleans represent logical values — true or false. They are often used in conditional statements and comparisons. Here’s an example: