const: This keyword is used to declare a constant variable, which means its value cannot be changed after it is assigned.
Primitive Data Types
- Number: Represents both integers and floating-point numbers.
- String: Represents a sequence of characters.
- Boolean: Represents a true or false value.
- Null: Represents an intentionally empty value.
- Undefined: Represents a variable that has been declared but not assigned a value.
- Symbol: Represents a unique, immutable value that can be used as an object property.
Non-Primitive Data Types
- Object: Represents a collection of properties and methods.
- Array: Represents an ordered list of elements.
- Function: Represents a reusable block of code that can be called with arguments and return a value.
- String: A sequence of characters, like "Hello, world!"
- Number: Numeric values, such as 42 or 3.14
- Boolean: True or false values
- Object: A collection of key-value pairs
- Array: A list of values, like [1, 2, 3]
- Undefined: A variable that hasn't been assigned a value
- Null: Represents an intentional absence of any value
const keyword followed by the variable name, an equals sign, the value, and then a semicolon. For example:
let when you plan to change the value of the variable later in your code. Use
const when you want to make the value constant and unchangeable.
You can use the
typeof operator returns a string representing the data type.
In this example, the
value variable's data type changes from 'number' to 'string'.
parseFloat(), or the unary
+ operator. Here are some examples: