Variables are used whenever there’s a need to store a piece of data. A variable contains data that can be used in the program elsewhere. Using variables also ensures code re-usability since it can be used to replace the same value in multiple places.
const currency = '$';let userIncome = 85000;console.log(currency + userIncome + ' is more than the average income.');// Output: $85000 is more than the average income.
Declaring a Variable
letis the preferred way to declare a variable when it can be reassigned. It is block scoped.
constis the preferred way to declare a variable with a constant value. It is also block scoped.
var age;let weight;const numberOfFingers = 20;
let movieTitle = '300'; // Stringlet audienceNumber = 300; // Number
- Anonymous contributors
- Anonymous contributorsAnonymous contributors