JS Assignment

JS Tutorial

JS Version

JS Objects

JS Function

JS Classes

JS Async

JS HTML DOM

JS Browser BOM

JS Web API

JS AJAX

JS JSON

JS vs JQUERY

JS Graphics

JavaScript Assignment

Assignment operators is used to assign values to JavaScript variables.

Operator

Example

Same As

=

x = y

x = y

+=

x += y

x = x + y

-=

x -= y

x = x – y

*=

x *= y

x = x * y

/=

x /= y

x = x / y

%=

x %= y

x = x % y

<<=

x <<= y

x = x << y

>>=

x >>= y

x = x >> y

>>>=

x >>>= y

x = x >>> y

&=

x &= y

x = x & y

^=

x ^= y

x = x ^ y

|=

x |= y

x = x | y

**=

x **= y

x = x ** y

Assignment Examples

The = assignment operator is used to assign a value to a variable.

Example

<!DOCTYPE html>

<html>

<body>

<h2>JavaScript Assignments</h2>

<h3>The = Operator</h3>

<p id=”demo”></p>

<script>

let x = 10;

document.getElementById(“demo”).innerHTML = x;

</script>

</body>

</html>

Output

JavaScript Assignments

The = Operator

10

The += assignment operator adds a value to a variable.

Example

<!DOCTYPE html>

<html>

<body>

<h2>JavaScript Assignments</h2>

<h3>The += Operator</h3>

<p id=”demo”></p>

<script>

let x = 10;

x += 5;

document.getElementById(“demo”).innerHTML = x;

</script>

</body>

</html>

Output

JavaScript Assignments

The += Operator

15

The -= assignment operator subtracts a value from a variable.

Example

<!DOCTYPE html>

<html>

<body>

<h2>JavaScript Assignments</h2>

<h3>The -= Operator</h3>

<p id=”demo”></p>

<script>

let x = 10;

x -= 5;

document.getElementById(“demo”).innerHTML = x;

</script>

</body>

</html>

Output

JavaScript Assignments

The -= Operator

5

The *= assignment operator multiplies a variable.

Example

<!DOCTYPE html>

<html>

<body>

<h2>JavaScript Assignments</h2>

<h3>The *= Operator</h3>

<p id=”demo”></p>

<script>

let x = 10;

x *= 5;

document.getElementById(“demo”).innerHTML = x;

</script>

</body>

</html>

Output

JavaScript Assignments

The *= Operator

50

The /= assignment divides a variable.

Example

<!DOCTYPE html>

<html>

<body>

<h2>JavaScript Assignments</h2>

<h3>The /= Operator</h3>

<p id=”demo”></p>

<script>

let x = 10;

x /= 5;

document.getElementById(“demo”).innerHTML = x;

</script

</body>

</html>

Output

JavaScript Assignments

The /= Operator

2

The %= assignment operator is used to assign a remainder to a variable.

Example

<!DOCTYPE html>

<html>

<body>

<h2>JavaScript Assignments</h2>

<h3>The %= Operator</h3>

<p id=”demo”></p>

<script>

let x = 10;

x %= 5;

document.getElementById(“demo”).innerHTML = x;

</script>

</body>

</html>

Output

JavaScript Assignments

The %= Operator

0


Notice: ob_end_flush(): failed to send buffer of zlib output compression (1) in /home/u212091429/domains/mydevhelp.com/public_html/wp-includes/functions.php on line 5420

Notice: ob_end_flush(): failed to send buffer of zlib output compression (1) in /home/u212091429/domains/mydevhelp.com/public_html/wp-includes/functions.php on line 5420