Open In App

What are Primitive Data Types in JavaScript ?

Last Updated : 29 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Primitive data types are the built-in data types provided by all programming languages. Examples of primitive data types in JavaScript are string, number, boolean, null, symbol, and undefined. These data types can store only a single value of a particular type in the memory.

The primitive data types are explained below:

  • String: It is a data type that stores the text values assigned using the double(” “) or single(‘ ‘) quotes.
  • Number: The number data type represents a numerical value either a floating point or an integer.
  • Boolean: It only contains the two values either true or false.
  • null: It refers to a variable that stores only null as its value.
  • Undefined: This data type means a variable that is declared but not yet initialized with a value.
  • Symbol: It is introduced in ES6. It creates a private object property by referring to that key only.

Example: The below code practically implements all the primitive data types available in JavaScript.

Javascript




const str = "GeeksforGeeks";
const num = 25;
let undef;
const nulled = null;
const workForce = Symbol(200);
const obj = {
    name: "GFG",
    desc: 'A Computer Science Portal.',
    [workForce]: 200
}
console.log(typeof str, typeof num, typeof undef,
    typeof nulled, typeof workForce
);
console.log(obj[workForce]);


Output

string number undefined object symbol
200


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads