Learn HTML,CSS, Python etc from the foundation

Tuesday, June 4, 2019

TOP 3 BASIC RULES IN NAMING JAVASCRIPT VARIABLES

No comments :

Hi, hope you’re doing fine? Today I’m gonna be discussing with you about the rules that governs JavaScript names. In case you’ve missed any of our previous lessons on JavaScript tutorial, please I beg you to pause this lesson and click HERE! This lesson will be a little bit complicated especially if you’re just joining us today. In our previous lessons, we’ve explained what variable is, and how it can be used in JavaScript. So today, we are going to be looking at the “dos” and “donts” or rather the criteria you need to consider while in naming a variable in JavaScript.
The rules are as follows
#RULE ONE
Do not include hyphen or asterisks while naming your variables in JavaScript. The reason is because both hyphen and asterisks are specially reserved for subtraction and multiplication.
#RULE TWO
There are certain words that are basically reserved as part of JavaScript syntax, hence these special words are not accepted in JavaScript as variable names so as to avoid unnecessary confusion. Some of these special reserved words include: private, import, long, try, loop, while, true, false, debugger, null, return, if, throw, instance of, var, break, delete, switch, else, do, float, int, Boolean, with, void, goto, catch, continue and so on.
However, if you must make use of any of these keywords, then you must make sure you change the case. For example, null to NULL.
#RULE THREE
Do not include any logical operator such as AND, OR, NOT etc., or mathematical operators in naming a variable in JavaScript.

WRAPPING UP
In our next lesson, we are going to put all these rules into practice. Make sure you master these three rules because most of the errors and frustrations that most newbies encounter in JavaScript pegs its fulcrum in flaunting these rules.


No comments :

Post a Comment