JS Startup

Challenges, Tips & Tricks & Tutorials

JavaScript Quiz – can use the reserved keyword as variable

JavaScript Quiz – can use the reserved keyword as variable

JavaScript Reserve Keyword –

In javascript, a reserved keyword is a keyword which not allow to use variables, labels, or function names.

Some of the reserved keywords are await, const, else, false, finally, if, import, int, new, let etc.

When used reserve keyword as a variable, function name, or labels then it throws an error.

For more detail about JavaScript Reserve Keyword click here.

JavaScript Question

In the javascript quiz, find out can we use the reserver keyword as a variable because the reserved keyword has some usage restriction.

First, we create variable name using let and assign an javascript string “Startup” to it.

let name = “Startup”;

Then, we print the value of name variable using console log.

console.log(name); // “Startup”

Now, we create another variable throw using let and assign “JS” which is javascript string to it.

let throw = “JS”;

Finally, we are printing the value of the variable throw using the console log. Any idea what should be the output of the above statement.

Answer – Error

Click To Run Code

Explanation

Now, you know the answer is “Error“. But why it just a normal variable. Let explain.

So, as firstly we used a name variable which is not a reserved keyword. That’s why no issue.

But in second variable, which is throw variable and throw is a reserved keyword. So, it can not be used as a variable name.

At last, That’s why we get an answer “Error“.

Let me know in the comment section, what you think about it.

I hope you understand the concept and logic behind it.

But wait, i have something more for you –

Check out our other javascript quiz – 

  1. JavaScript Quiz – Infinity number is a true or false value
  2. JavaScript Quiz – array single value comparison can be possible
  3. JS Quiz – compare the self value with data type
  4. JS Quiz – can NaN be really equal to NaN

Conclusion

To participate in our javascript quiz or challenges, tutorial, tips & tricks make sure to join our jsstartup newsletter. So, you can able to participate in our daily challenges & learn the javascript concept.

And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page

If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top
0 Shares
Share via
Copy link