Skip to content
Foxipa

Suggest an edit

Tell us what should be corrected, clarified, or improved. Submission will be connected to Foxipa’s contribution service later.

No information is sent anywhere yet. Your suggestion is only prepared in your browser.

Learning

JavaScript Variables and Values

Learn how JavaScript variables hold values and see the result immediately in an editable browser example.

Levels: Beginner ~12 min read

Basic

A JavaScript variable gives a value a name so your program can refer to that value later. Modern JavaScript commonly uses let for values that may be reassigned and const for bindings that should not be reassigned.

javascript
const language = "JavaScript";
let learners = 1;
learners += 1;

console.log(language);
console.log(learners);

Edit and run the example

The HTML file provides the document, the CSS file provides its presentation, and the JavaScript file changes the document and writes to the example console. Try changing the values, then run the example.

Interactive Runnable example
Edit

Ready to run.

What to notice

  • The variable name lets the program refer to a value without repeating the value itself.

  • The let binding can be reassigned.

  • The JavaScript file can read and change elements in the HTML document.

Was this page helpful?

Mark this learning resource complete to track your learning progress.