JavaScript: Primitive Data Types

So data types, what are they? Are they essential? Yes, they are, and you must know about data types.

  • Datatypes are something familiar in all programming languages
  • But in javascript, as it is a dynamically types engine, all the data types are dynamic.
  • This is very convenient as we don't have to declare a data type when we create a variable.
  • There are var, const, let keywords in javascript, and we need to use them to specify the datatype for the declared variable.

Ok, let us dive into some of the primitive data types of javascript.

1. String:

  • If you want to store some exemplary texts in a variable, the string is your best pal.
  • Strings in javascript can be called in between a "" or '' or `` too.
var name = 'Mario'



2. Number:

So basically, number in javascript means that the dynamic language has the datatypes of int, float, exponentials, long.

var number = 2000000
var fl = 22.33
var ex = 40e5

console.log(typeof(number) ,typeof(fl), typeof(ex))


number number number 

3. Boolean:

  • So boolean is a datatype that points in the direction of yes/no.
  • Think of it as a switch between yes and no.
  • So basically represented by true or false.
var orderDelivered = true;
var notDelivered = false;

4. Undefined:

  • Undefined is where we declare a variable, and if we don't assign values to that variable, it'll automatically throw it as undefined.
  • This means it has no value to it currently because of the unassignment.
let matrix;



5. Null:

  • Null is an empty pot without any water in it waiting to be filled up anytime later.
  • It is a variable with an empty value, or we can say it is an unknown value.
let matrix2 = null;




Javascript closely follows the dynamic pattern of datatype assignment, so it is a main convenient feature if we can call it.

Fri, 09/24/2021 - 09:10

Authored by

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.