Reserved Keywords
EasyIn plain terms
Reserved keywords like if, for, function, return cannot be used as variable names. Avoid naming variables after built-in objects (e.g., name, length) to prevent shadowing.
What you need to know
- •if, else, for, while, function, return, etc.
- •Cannot use as identifiers
- •Contextual keywords (await, yield)
Try it yourself
Copy the code below and run it in your browser console or a code editor:
// Invalid - reserved
// let if = 1;
// const for = 2;
// Valid
let myIf = 1;
const loopCount = 10;
// Avoid - shadows built-in
// let name = 'John'; // name is a global property
const userName = 'John'; // BetterLearn more
Dive deeper with these trusted resources: