JavaScript data types

JavaScript data types

·

2 min read

Table of contents

No heading

No headings in the article.

As we all know that JavaScript is a single-threaded, non-blocking, asynchronous, concurrent programming language with lots of flexibility.

We should also keep in mind that JavaScript is a dynamically-typed language, which means that variables can hold values of different data types. Here are some of the most common data types in JavaScript, along with examples:

  1. Numbers: This data type includes both integers and floating-point numbers. Example: const age = 28;

  2. Strings: This data type represents text and is enclosed in single or double quotes. Example: const name = 'John';

  3. Booleans: This data type has only two possible values: true and false. Example: const isOnline = true;

  4. Undefined: This data type represents a variable that has been declared but not assigned a value. Example: let occupation;

  5. Null: This data type represents a variable with no value. Example: const car = null;

  6. Objects: This data type is used to store collections of data in key-value pairs. Example:

yamlCopy codeconst person = {
  name: 'John',
  age: 28,
  isOnline: true
};
  1. Arrays: This data type is used to store ordered collections of data. Example: const fruits = ['apple', 'banana', 'orange'];

In conclusion, understanding JavaScript data types is essential for writing efficient and effective code. By knowing which data types to use in different situations, developers can write cleaner, more readable code that performs better and is easier to maintain.