Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

JavaScript Arithmetic

Similar to algebra, arithmetic operations can be performed with JavaScript variables, employing operators such as = and +.

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 Dollar Sign $

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 Underscore (_)

JavaScript considers the underscore as a valid character for identifiers, making identifiers containing _ acceptable as variable names.

Example

let _lastName = “Johnson”;
let _x = 2;
let _100 = 5;