Difference between var, let, const in Javascript

//Example 1
var language="javascript";
language="JavaScript is the world's most popular programming language"; // New Value Assignedconsole.log(language);//Output//JavaScript is the world's most popular programming language//Example 2
function LanguageExample() {
var likes = 500;
console.log(likes); //Output:- 500
}
console.log(likes);//ReferenceError: likes is not defined (we can not access outside the function . only accessible inside function)
function LanguageExample() {
let likes = 500;
console.log(likes); //Output:- 500
}
console.log(likes);//ReferenceError: likes is not defined (Unable to access outside the function block)
// Example 1
const language="javascript";
language="JavaScript is the world's most popular programming language"; // Uncaught TypeError: Assignment to constant variable.
//Example 2
function LanguageExample() {
const likes = 500;
console.log(likes); //Output:- 500
}
console.log(likes);//ReferenceError: likes is not defined

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store