What are JavaScript Data Types?

In JavaScript, there are six primitive data types: string, number, boolean, null, undefined, and symbol.

  1. string: This data type is used to represent a sequence of characters, such as words or sentences. A string value must be surrounded by quotes. You can use single or double quotes, but you must use the same type of quotes at the beginning and the end of the string. For example: "Hello, world!" or 'Hello, world!'.
  2. number: This data type is used to represent numeric values. JavaScript has only one type of number, which can be either an integer (a whole number) or a floating-point number (a number with a decimal point). For example: 10, -5, 3.14, 0.01.
  3. boolean: This data type is used to represent logical values. It has only two possible values: true and false. For example: true, false.
  4. null: This data type is used to represent the absence of a value. It has only one possible value: null. For example: null.
  5. undefined: This data type is used to represent a variable that has not been assigned a value. It has only one possible value: undefined. For example: undefined.
  6. symbol: This data type is used to create unique identifiers for objects. It was introduced in ECMAScript 2015 and is a relatively new addition to the language. Symbols are typically used to create object properties that can’t be accessed or modified using the normal dot notation. For example: Symbol("foo").

Here are some examples of using these data types in JavaScript:

// Declaring a string variable
var name = "John";

// Declaring a number variable
var age = 35;

// Declaring a boolean variable
var isMarried = true;

// Declaring a null variable
var height = null;

// Declaring an undefined variable
var salary;

// Declaring a symbol
var id = Symbol("foo");

// Declaring an object
var person = {
  name: "John",
  age: 35,
  isMarried: true,
  height: null

In addition to these primitive data types, JavaScript also has a compound data type called object. An object is a collection of key-value pairs, and it can be used to represent complex data structures such as array, set, map, and so on.

I hope this helps! Let me know if you have any questions.