DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 964,423 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for Javascript DataTypes

Posted on • Originally published at

Javascript DataTypes

In this tutorial, You'll be learning about using datatypes in Javascript.


let x = 16; //now x is interger
x = 12.65; //now x value is updated to float
x = "JavaScript is Amazing."; //now x value is updated to string

JavaScript is Amazing.

DataType types


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

let task_one = "Complete Homework<br>";
let task_two = 'Complete Homework<br>';
let task_three = `Complete Homework<br>`; //this is called string literals


Complete Homework
Complete Homework
Complete Homework

String Concatenation

Using + Operator

let name = "John";
let age = 25;
let sentence = name+" is "+age+" years old";

John is 25 years old

Using String Literals

let name = "John";
let age = 25;
let sentence = `${name} is ${age} years old`;

John is 25 years old


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");

I’ve included link to the whole chapter here.

Top comments (0)

Classic DEV Post from 2020:

js visualized

🚀⚙️ JavaScript Visualized: the JavaScript Engine

As JavaScript devs, we usually don't have to deal with compilers ourselves. However, it's definitely good to know the basics of the JavaScript engine and see how it handles our human-friendly JS code, and turns it into something machines understand! 🥳

Happy coding!