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 contributorsAnonymous contributors
- Anonymous contributors
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.