Skip to content
techsnow

JavaScript Basics

Variables

Variables are named containers for values. JavaScript has three keywords to create them.

Syntax:

const name = "Ayesha";  // can't be reassigned
let score = 10;         // can be reassigned
score = score + 5;

console.log(name, score);

Output

Ayesha 15
KeywordReassign?ScopeUse it?
constNoBlockYes, by default
letYesBlockYes, when the value changes
varYesFunctionNo, it's the old way

Naming rules

  • Names can contain letters, digits, _ and $, but can't start with a digit.
  • Use camelCase: firstName, totalPrice, isLoggedIn.
  • Choose meaningful names: price is better than p or x.
  • You can't use reserved words like let, if or function.