In this tutorial, you will learn about variable naming conventions with examples in javascript, so while naming your variable keep this rule in your mind.
Following are the variable naming convention.
let num = 5; // correct
let $num = 5; // correct
let _num = 5; // correct
let 5num = 5; // wrong
/* variable contain number, letters or dollar signs ($) */
let num1$ = 10; // correct
/* variable should not contain space */
let first name = 'studyfame' // wrong
/* variable should not contain dot */
let na.me = 'studyfame' // wrong
/* variable should not contain dash(-) */
let na-me = 'studyfame' // wrong
shop
and Shop
would be different variable names, but it is bad practice to create two variable names that have the same using different cases. keywords
or reserved words
. Keywords are special words that tell the interpreter to do something. For example, var, let, const, is a keyword used to declare a variable. you cannot use reserved words for variable naming because reserved words are ones that may be used in a future version of JavaScript.firstName
rather than firstname