Skip to content

04 Data Type

Biswajit Sundara edited this page May 1, 2023 · 2 revisions

Java Script supports primitive data types - String, Number, Boolean & composite data types such as object, array, regular expression.

1. String Data Type

//string values with single quote
let fname='Biswajit'
console.log(fname);

//string values with double quote
let lname="Sundara"
console.log(lname);

//when we have a single quote inside the string then use double quotes else it will error
let para="I've a pen"
console.log(para);

2. Template Literals (Usage of Back Ticks)

Now a days back ticks are widely used. We can use $ symbol and the variable directly when we use back ticks. Look at the example below.

let fname='Biswajit'
console.log("My name is" +fname);
console.log(`My name is ${fname}`);

3. Number Data Type

let age=30
console.log(age);

let salary=33.33
console.log(salary);

4. Boolean Data Type

let married=true
console.log(married);

5. How to check the data type of variable

We can check the data type of variable using typeof keyword.

let name="biswajit";
let strype= typeof name;
console.log(strype);

let age=30;
let numtype=typeof age;
console.log(numtype);

let married=true;
let blntype=typeof married;
console.log(blntype);

Clone this wiki locally