Example
let x = 5 + 2 + 3; |
In addition to numerical operations, you can concatenate strings in JavaScript, resulting in their combination.
Example
let x = “John” + ” “ + “Doe”; |
You can also experiment with this.
Example
let x = “5” + 2 + 3; |
Note When a number is enclosed in quotes, JavaScript interprets the subsequent numbers as strings, resulting in concatenation. |
Now try this:
Example
let x = 2 + 3 + “5”; |
JavaScript regards a dollar sign as a valid character for identifiers, thus identifiers containing $ are considered valid variable names.
Example
let $ = “Hello World”; let $$$ = 2; let $myMoney = 5; |
Although not particularly common in JavaScript, professional programmers frequently employ the dollar sign as an alias for the main function in JavaScript libraries.
For example, in the jQuery library, the primary function $ is utilized to select HTML elements. In jQuery, $(“p”); signifies “select all p elements”.
JavaScript considers the underscore as a valid character for identifiers, making identifiers containing _ acceptable as variable names.
Example
let _lastName = “Johnson”; |