JAVASCRIPT Variables:)

JAVASCRIPT Variables:)ASHWINTH

** JavaScript Variables: let, const, and var** JavaScript provides three keywords to declare...

** JavaScript Variables: let, const, and var**

JavaScript provides three keywords to declare variables: let, const, and var.

let

let is used when a variable's value may change.

javascript
let age = 20;
age = 21;

Enter fullscreen mode Exit fullscreen mode

const

const is used when a variable should not be reassigned.

javascript
const name = "John";
Enter fullscreen mode Exit fullscreen mode

Trying to change it will cause an error:

name = "Mike"; // Error
Enter fullscreen mode Exit fullscreen mode

var

var is the older way to declare variables in JavaScript.

var city = "Chennai";
city = "Mumbai";
Enter fullscreen mode Exit fullscreen mode

In modern JavaScript, let and const are generally preferred over var because they have clearer scoping rules.

Quick Summary

  • let → value can be changed
  • const → value cannot be reassigned
  • var → older variable declaration method

Understanding these three keywords is an essential first step in learning JavaScript.