Bindings and Variables 1...

Bindings and Variables 1...

How distinguish between var ,let and const statements

·

2 min read

Table of contents

Intro

Hi,I'm Abraham. I started JavaScript two years ago but seriously started studying the language this year.I have had obstacles and times where I nearly gave up,the fun is later understanding the answers to problems😊.

Back to business

Before go into that we should have a basic understanding of Bindings:They are statements which hold(bind) variables and assign to values of different data types.

•Var This a statement that can be used globally and locally in script page.By locally I mean,I can be called in a function. It is also mutable that is its variable value can be changed.


var x= 5;//assigned a variable
document.write(x);//=>5
x=0;//reassigned

document.write(x);=>0

💡Note:var is oldest of bindings and is not commonly used

•let Let is statement that can be declared or assigned a value globally but can only be called in block function.That us can only be called locally.Block like "var" is mutable out globally.


let x= 5;//assigned a variable
My function{
document.write(x);//=>5
}
Myfunction();
x=0;//reassigned
 document.write(x);//=>0

•const const statement is used ,well as the name implies to declare immutable constants.Once declared and assigned a variable the const statement can never be changed. It is globally and locally used.


const x= 5;//assigned a variable
My function{
document.write(x);//=>5
}
Myfunction();
const x=0;//reassigned
 document.write(x);//=>5

😊I'm a young web developer ready to learn and correct my mistakes. For any complaints http:wa.me//+2347010796290

Â