Javascript Data-Types | strings, string-literals, boolean, null and numbers

JavaScript is a loosely typed language which means we can store any type of data in a variable without specifying its type.


DataType types


Strings are a sequence of characters wrapped in double or single quotes.
Below ways, we can assign Strings

String Concatenation

We can join variables to strings using `+` Operator or use string literal which is the best way.

Using + Operator

Using String Literals`


Adding two numbers

let a=5,b=7;
let z=a+b;

Add number and string

let a=5;
let b="7";
let z=a+b;
alert(z); //output 57

null type

If we don’t want to initialize the value to variable than we can use null which basically means nothing.

let designation=null
alert(designation); // outputs null

undefined type

If we declare variable but don’t initialize its value than the value of the variable will be undefined.

let name;
alert(name); //outputs undefined

Boolean Date-Type

Boolean types have two values that are true or false. We can also assign 1 which means true and 0 which means false.

let has_completed_howework=true;
alert(has_completed_howework); //outputs true

We can use this for conditional checking

let has_completed_howework=true;
    alert("Student has completed homework");
    alert("Student has not completed homework");


Objects are special datatypes using them we can store different variable values with different data types. Objects will be covered in the coming tutorial in detail.

Other Javascript Posts