Lets, explore the primitive data types of javascript

Rijwanul Alam
2 min readMay 6, 2021
types of data in javascript

We all know that JavaScript is a high-level scripting language used both on the client-side and server-side. In JavaScript, we have two types of data.

  1. Primitive data types.
  2. Non-primitive data types.

Today we brush up on our intelligence about primitive data types.

There are six primitive data types in javascript we have.

  1. Number
  2. String
  3. Boolean
  4. Null
  5. Undefined
  6. Symbol

Let’s discuss primitive data types of javascript shortly.

  1. Number

The number is a primitive wrapper object used to represent and manipulate numbers. The Number constructor working with numbers. Number() function is used to convert the other types of values into numbers.

const a = 60; // a holding a number

2. String

A javascript string stores a series of characters. A string can be any text inside double or single quotes.

const charName1 = "mukhles ali"
const charName2 = "halum mia"

String indexes are zero-based: The first character is in position 0, the second in 1.

3. Boolean

JavaScript has a Boolean data type. It can only take the values true or false. If the value parameter is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (“”), the object has an initial value of false.

var YES = true;
var NO = false;

if(YES)
{
alert("This code block will be executed");
}

if(NO)
{
alert("This code block will not be executed");
}

4. Null

It is one of JavaScript’s primitive values and is treated as falsy for boolean operations.

var foo = null;
foo; //null

5. Undefined

The undefined property indicates that a variable has not been assigned a value, or not declared at all. null is an assigned value. It means nothing. undefined typically means a variable has been declared but not defined yet.

var x;
if (typeof x === 'undefined') {
// these statements execute
}

6. Symbol

Symbols are completely unique primitive javaScript identifiers. Symbols are immutable (cannot be changed) and are unique. To create a new primitive symbol, you write Symbol() with an optional string.

let sym1 = Symbol()
let sym2 = Symbol('foo')
let sym3 = Symbol('foo')

The above code creates three new Symbols. Note that Symbol("foo") does not coerce the string "foo" into a Symbol. It creates a new symbol each time:

Symbol('foo') === Symbol('foo')  // false

These are the primitive data types of javaScript.

Thanks all for reading my article. If you have any tips or any ideas you can share them in the comment box.

--

--

Rijwanul Alam
0 Followers

Full Stack Web Developer (MERN). A dedicated learner about web development. I am always excited to learn trendy technology and love to build web application.