DEV Community

Vidya
Vidya

Posted on

Datatypes and Variables in JavaScript

What is a Variable?
A variable is like a container that holds information(data).
Think of it as a box where you can store a value - a number, a word, or even a list of items.

How to declare a variable:
JavaScript gives us three ways to declare a variable:
var name="abcd";
let age=24;
const country="india";

JavaScript Data Types:
1.Primitive Data Types:
String --> example: let name = "Hello";
Number --> example: let age=25;
Boolean --> example: let isStudent=True;
Undefined -->example: let x; (variable declared but not given a value)
NUll --> example: let y=null;(Empty value)
Symbol --> example: let id = symbol("id")
BigInt --> 12345678901234n (very large numbers)

2.Non-Primitive Data Types:

Object --> example: {name:"Hello",age:25} (Group of key-value pairs)
Array --> example: let num=[10,20,30] ; (list of items)
Function --> example: function add(){} (Block of code)

Top comments (0)