0% found this document useful (0 votes)
3 views

Unit 3 of computer science

The document provides examples of JavaScript operators, specifically focusing on arithmetic and assignment operators. It includes HTML and JavaScript code snippets that demonstrate the use of various arithmetic operations such as addition, subtraction, multiplication, division, and modulus, as well as assignment operations. Each example updates the HTML content to display the results of the operations performed.

Uploaded by

Harsh Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Unit 3 of computer science

The document provides examples of JavaScript operators, specifically focusing on arithmetic and assignment operators. It includes HTML and JavaScript code snippets that demonstrate the use of various arithmetic operations such as addition, subtraction, multiplication, division, and modulus, as well as assignment operations. Each example updates the HTML content to display the results of the operations performed.

Uploaded by

Harsh Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Script Operator

Some example

1. Arithmetic Operator

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arithmetic</h1>
<h2>The + Operator</h2>
<p id="demo"></p>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<p id="demo4"></p>
<p id="demo5"></p>

<script>
let x = 5;
let y = 2;
let z = x + y;
document.getElementById("demo").innerHTML = z;

let k= x - y;
document.getElementById("demo1").innerHTML = k;

let m = x * y;
document.getElementById("demo2").innerHTML = m;

let div = x / y;
document.getElementById("demo3").innerHTML = div;

let mod = x % y;
document.getElementById("demo4").innerHTML = mod;

x++;
let increment= x;
document.getElementById("demo5").innerHTML = increment;
</script>
</body>
</html>
2. Assignment operator:
<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Assignments</h1>
<h2>Simple Assignment</h2>
<h3>The = Operator</h3>

<p id="demo"></p>
<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<p id="demo4"></p>

<script>
let x = 10;
document.getElementById("demo").innerHTML = "Value of x is: " + x;

let y=60;
let x = 10 + y;
document.getElementById("demo1").innerHTML = "Value of x is: " + x;
let k=10;
k += 5;
document.getElementById("demo2").innerHTML = "Value of x is: " + k;

let text = "Hello";


text += " World";
document.getElementById("demo3").innerHTML = text;

let a = -100;
a <<= 5; // left shift operator shift by 5 bit
document.getElementById("demo").innerHTML = "Value of a is: " + a;
</script>

</body>
</html>

You might also like