In JavaScript, reserved words (keywords) are special words that have a predefined meaning in the language. Because of that, you cannot use them as variable names, function names, or identifiers . let if = 10; // ❌ Error var class = "JS"; // ❌ Error function for() {} // ❌ Error Common Reserved Words Some important keywords include: if , else for , while , do function , return var , let , const class , extends try , catch , finally switch , case , break new , this , typeof How to “use” reserved words correctly You don’t use them as names — instead, you use them for their intended purpose . 1. Using if (condition) let age = 18; if (age >= 18) { console.log("Adult"); } 2. Using for (loop) for (let i = 0; i < 5; i++) { console.log(i); } 3. Using function function greet() { return "Hello!"; } Trick to Remember Reserved words = instructions for JavaScript , not names you create. Special Case (Advan...
Comments
Post a Comment