Menu
Posted At Tue, Oct 17, 2023 4:35 AM

JavaScript Primitive Types

Listen | 2 min read

Table of Contents

1. Introduction to JavaScript Primitive Types
2. Number
3. String
4. Boolean
5. Undefined
6. Null
7. Symbol
8. BigInt
9. Checking Primitive Types
10. Conclusion

1. Introduction to JavaScript Primitive Types

In JavaScript, data types are categorized into primitive types and reference types. This article focuses on the primitive types in JavaScript, which include numbers, strings, booleans, undefined, null, symbols, and big integers.

2. Number

Numbers in JavaScript can be integers or floating-point values.

Example:

let integer = 42;
let float = 3.14;

3. String

Strings represent textual data in JavaScript.

Example:

let text = 'Hello, World!';

4. Boolean

Boolean values are either true or false.

Example:

let isTrue = true;
let isFalse = false;

5. Undefined

A variable that has been declared but has not been assigned a value is undefined.

Example:

let uninitializedVar;
console.log(uninitializedVar); // Output: undefined

6. Null

null is a special value that represents the intentional absence of any object value.

Example:

let emptyValue = null;

7. Symbol

Symbols are unique and immutable values, often used as object property keys.

Example:

const uniqueSymbol = Symbol('description');

8. BigInt

BigInt
is a numeric primitive type for representing large integers.

Example:

const bigIntValue = 9007199254740992n;

9. Checking Primitive Types

You can use the typeof operator to check the data type of a value.

Example:

typeof 42; // Output: 'number'
typeof 'Hello'; // Output: 'string'
typeof true; // Output: 'boolean'
typeof undefined; // Output: 'undefined'
typeof null; // Output: 'object' (historical quirk)
typeof Symbol('test'); // Output: 'symbol'
typeof 9007199254740992n; // Output: 'bigint'

10. Conclusion

Understanding JavaScript primitive types is crucial for working with data effectively. By grasping the nuances of numbers, strings, booleans, undefined, null, symbols, and big integers, you'll be better equipped to write reliable and efficient JavaScript code.

Next one is learning about JavaScript Object.

Click this link!
JavaScript Object

1466 1

Comments