0% found this document useful (0 votes)
12 views3 pages

08 Operators

JavaScript operators are used to assign values, perform arithmetic operations, and concatenate strings. The assignment operator (=) assigns values to variables, while arithmetic operators (+, -, *, /, %) perform math operations. The + operator can also concatenate strings by adding them together. When adding a number and a string, the result will be a string.

Uploaded by

BaneeIshaqueK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views3 pages

08 Operators

JavaScript operators are used to assign values, perform arithmetic operations, and concatenate strings. The assignment operator (=) assigns values to variables, while arithmetic operators (+, -, *, /, %) perform math operations. The + operator can also concatenate strings by adding them together. When adding a number and a string, the result will be a string.

Uploaded by

BaneeIshaqueK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

JavaScript Operators

= is used to assign values.


+ is used to add values.
The assignment operator = is used to assign values to JavaScript variables.
The arithmetic operator + is used to add values together.
y=5;
z=2;
x=y+z;
The value of x, after the execution of the statements above is 7.
JavaScript Arithmetic Operators
Arithmetic operators are used to perform arithmetic beteen variables and!or values.
"iven that y=5, the table belo explains the arithmetic operators#
Operator Description Example Result
+ Addition x=$+% x=7
& Subtraction x=$&% x='
( )ultiplication x=$(% x=*+
! ,ivision x=$!% x=%.-
. )odulus /division remainder0 x=$.% x=*
++ 1ncrement x=++$ x=2
&& ,ecrement x=&&$ x=3
JavaScript Assignment Operators
Assignment operators are used to assign values to JavaScript variables.
"iven that x=10 and y=5, the table belo explains the assignment operators#
Operator Example Same As Result
= x=$ x=-
+= x+=$ x=x+$ x=*-
&= x&=$ x=x&$ x=-
(= x(=$ x=x($ x=-+
!= x!=$ x=x!$ x=%
.= x.=$ x=x.$ x=+
The + Operator 4sed on Strings
The + operator can also be used to add string variables or text values together.
To add to or more string variables together, use the + operator.
txt1="What a very";
txt2="nice day";
txt3=txt1+txt2;
After the execution of the statements above, the variable txt' contains 56hat a ver$nice da$5.
To add a space beteen the to strings, insert a space into one of the strings#
txt1="What a very ";
txt2="nice day";
txt3=txt1+txt2;
or insert a space into the expression#
txt1="What a very";
txt2="nice day";
txt3=txt1+" "+txt2;
After the execution of the statements above, the variable txt' contains#
56hat a ver$ nice da$5
Adding Strings and 7umbers
The rule is# If you add a number and a string t!e result "ill be a string#
8xample
x=5+5;
document.write(x);
x="5"+"5";
document.write(x);
x=5+"5";
document.write(x);
x="5"+5;
document.write(x);

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy