Data Types and Keywords

JavaScript Data Types and Keywords.

JavaScript

Data Types

Data types represent the kind of data that can be used and manipulated within a program. Here are the primary data types in JavaScript:

Primitive Data Types:

1. Number: Represents numeric values, including integers and floating-point numbers.

2. String: Represents sequences of characters, enclosed within single (''), double ("") or backticks (``).

3. Boolean: Represents a logical value, either 'true' or 'false'.

4. Undefined: Represents a variable that has been declared but not assigned a value.

5. Null: Represents an intentional absence of any object value.

6. Symbol (added in ECMAScript 6): Represents a unique and immutable value, often used as object property keys.

7. BigInt (added in ECMAScript 2020): Represents integers of arbitrary precision, useful when working with very large numbers.

Composite Data Types:

1. Object: Represents a collection of key-value pairs, where values can be accessed by keys. Objects can be created using object literals '{}', constructors, or classes.

2. Array: Represents a list-like collection of elements, which can be of any data type. Arrays are ordered and can be accessed by index. They are created using array literals '[]'.

3. Function: Represents executable code. Functions are objects in JavaScript, and they can be assigned to variables, passed as arguments, and returned from other functions.

4. Date: Represents dates and times.

5. RegExp: Represents regular expressions for pattern matching with strings.

Special Data Types:

1. NaN: Represents "Not-a-Number" value, returned when a mathematical operation is performed, but the result is not a valid number.

2. Infinity and -Infinity: Represent positive and negative infinity, returned when a number exceeds the upper limit of the floating-point numbers.

Note: JavaScript is a dynamically typed language, meaning you don't need to specify the data type of a variable explicitly; it is inferred by the interpreter.

Tabular representation of JavaScript data types:

Data Type Description Example
Number Represents numeric values, including integers and floating-point numbers. let num = 42;
String Represents sequences of characters. let str = 'Hello'
Boolean Represents a logical value, either 'true' or 'false' let bool = true;
Undefined Represents a variable that has been declared but not assigned a value. let undefinedVar;
Null Represents an intentional absence of any object value. let nullVar = null;
Symbol Represents a unique and immutable value, often used as object property keys. const sym = Symbol();
BigInt Represents integers of arbitrary precision. const bigIntNum = 123n;
Object Represents a collection of key-value pairs. const obj = {};
Array Represents a list-like collection of elements. const arr = [];
Function Represents executable code. function foo() { ... }
Date Represents dates and times. const now = new Date();
RegExp Represents regular expressions for pattern matching with strings. const regex = /pattern/;
NaN Represents "Not-a-Number" value, returned when a mathematical operation is not a valid number. const notANumber = NaN;
Infinity Represents positive infinity, returned when a number exceeds the upper limit of floating-point numbers. const posInfinity = Infinity;
-Infinity Represents negative infinity, returned when a negative number exceeds the lower limit of floating-point numbers. const negInfinity = -Infinity;

Keywords

JavaScript keywords are reserved words that have special meanings and purposes within the language. These keywords cannot be used as identifiers (such as variable names or function names) in JavaScript. Here's a list of JavaScript keywords .

Note: You cannot use these keywords as identifiers in your JavaScript code, such as variable names, function names, or labels.

What's Next?

We've now entered the finance section on this platform, where you can enhance your financial literacy.