Understanding Variables and Data Types in JavaScript
Know about variable declaration , primitive data types and scoping in JavaScript

I have joined and started learning Software development with ChaiCode Web dev Cohort 2026 and very excited😊
Search for a command to run...
Know about variable declaration , primitive data types and scoping in JavaScript

I have joined and started learning Software development with ChaiCode Web dev Cohort 2026 and very excited😊
No comments yet. Be the first to comment.
this series includes all about Javascript which I will learned in Chaicode Webdev cohort 2026.
Understanding Date Object of JavaScript
Lets differentiate and understand about global and globalThis used in nodejs or any JS ecosystem like whether it will be in browser , nodejs, deno, web workers etc. What is global ? global means glo
Lets learn about path module of nodejs path module helps to get files and directory and works with it and write code for cross platform code . like getting files from any operating system like macos,
The virtual DOM is a lightweight copy of the real DOM that allows React to manage changes more efficiently by minimizing the direct manipulation required on the real DOM. This process significantly en
About template literal , use case and reasons of bringing it and benefits

why do it need to flatten array and various ways of flatten the array

There are a lot of saying that variable is container and box to store different type of value in memory . It is just label to the value so whenever It needed we can directly used by variable name and the value is placed in place of variable name. let say in glass we can drink water, milk , juice any liquid type data so glass is variable . same way In programming, It is used to hold value.
In this article , we discussed about variable and data type in JavaScript.
It is the name given to the value which is stored in the memory and It is used to access and manipulate the value by variable throughout the program. It is holding the information which can access or change during execution of program.
It is used because of following reasons :It provide name to the value that gonna be stored in memory so It can easily accessed and manipulated during the execution of program
Characteristics of Variables :
Named Storage : It is name which is also called identifier that is given to the memory location where data can be stored. let x = 5 ;
Dynamic Values : The value of variable can change during execution of program . x = x+10;
Data types : It can hold different types of data like number, string, boolean etc.
Scope : The variable has scope . It means where the variable are accessible in the program. If it is bloc scope then it is not accessible outside of that block . global scope variable is accessible overall the program . It depends upon use case in which scope you want to define the variable.
// declaring and initializing the variable
var yourName = "Lollipop" ;
var price ; // declaring
price = 5 ; // initializing
// used in expressions
const info = "Hi I am " + yourName + " and my price is Rs." + price ;
console.log(info) ; // Hi I am Lollipop and my price is Rs.5
// updating the values
price = 10 ;
console.log("Price : ", price) ; // Price : 10
// const variable cannot change
const gender = male ;
gender = female ; // Error : Assignment to const variable
There are certain rules for declaring the name of variable in JavaScript . They are :
It only starts with letters or $ or _ .
It doesnot start with numbers like let 1num = 10 ;
No reserved words are allowed to used as variable . There are some reserved words of language like let , const , function , for, some, every , this, while, do, if, else, class, extends, and many which is keywords which is used in programming in JavaScript.
There is convention to write the variable name in camelCase and it must be descriptive and meaningful because It is name and name must be descriptive which is very useful to understand about the code what it is used for .
No space is allowed and others special characters in the name of variable .
There are 3 ways of declaring variables in JavaScript . by using var, let and const . But In Today modern JavaScript we used let and const only .
var is traditional way before es6 . It has few issues .
It is function scoped .
It creates variable in global window object .
It get hoisted means we can access it before declare in code .
but let and const are introduced in es6 and it is block scoped and solve the problems which is in var .
let is same as var by varying nature . It value can be changed during the program but const is constant . it value cannot be changed throughout the program and we need to initialize in one line . like const myName = "Dipesh" ;
Primitive means It is single value and stored and copied by value . There are 7 different primitive types . They are
// primitive data types
// 1. number
let a = 10 ;
let total = 200.78 ;
let balance = 25_00_000 ;
let age = 23 ;
// 2. string
let userName = "Dipesh Chaudhary" ;
let getIn = "Chaicode Cohort 2026" ;
// 3. Boolean
let isCohortStd = true ;
let isRude = false ;
// 4. null
let gf = null ;
// 5.undefined
let job ;
// 6. bigint
let aura = 999999999999999999n; // we can say Infinity
// 7. Symbol
const nationalId = Symbol("Dipesh") ;
Scope is the place where we can access the value of variable.
There are Block and Global scope in JavaScript.
// scoping discussion
console.log(userName) ; // global scope
// not inside any function means global
function goToGym(gymName) {
console.log("Gym name is ", gymName)
}
goToGym("BodyBuilder")
// console.log(gymName); // gymName is not accessible
// ReferenceError: gymName is not defined
// we can give block scope by curly braces
{
let myCount = 98 ;
const myBirthPlace = "Lahan" ;
const myMotherTongue = "Tharu , Maithili " ;
}
// console.log(myCount) ;
// if variable name is not found suppose inside function , or any block like if
// then it look up outside of it which is also called variable lookup
// it is called scope chain
Feature | var | let | const |
Scope | Functional Scope | Block Scope | Block Scope |
Redeclaring | Allowed | Not Allowed | Not Allowed |
Reassigning | Allowed | Allowed | Not Allowed |
Hoisting | Hoisted (initialized as | Hoisted (but uninitialized) | Hoisted (but uninitialized) |
Temporal Dead Zone | No | Yes | Yes |
Temporal Dead Zone (TDZ) is the area before declaration and initialization of let and const variable where we cannot access the value before assign the value.
The variable is container like a box which holds the reference of memory location where value is stored. I hope It is worth for reading and understanding the variable and scoping of variable.