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

Operators and Expressions

The document discusses different types of operators in JavaScript including assignment, arithmetic, string, boolean, logical operators. It provides examples of each operator and the values they return. It emphasizes thinking through the logic of what you want the code to do before writing it.

Uploaded by

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

Operators and Expressions

The document discusses different types of operators in JavaScript including assignment, arithmetic, string, boolean, logical operators. It provides examples of each operator and the values they return. It emphasizes thinking through the logic of what you want the code to do before writing it.

Uploaded by

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

INTERACTIVITY

01.06 Operators and Expressions WITH JAVASCRIPT

Operators and Expressions


INTERACTIVITY
01.06 Operators and Expressions WITH JAVASCRIPT

Statements
• We have been using statements to
execute our JavaScript code
• Statements often have expressions
• Expressions produce values
INTERACTIVITY
01.06 Operators and Expressions WITH JAVASCRIPT

Expression
• So if you think back to LHS = RHS, the
LHS is a variable and the RHS is what
generates the value
• What are our tools for generating values
on the RHS?
INTERACTIVITY
01.06 Operators and Expressions WITH JAVASCRIPT

Assignment Operators
Operator Example Value stored in x
= x=5 5
y = 12
=
x=y 12
INTERACTIVITY
01.06 Operators and Expressions WITH JAVASCRIPT

Arithmetic Operators
Operator Example Value stored in x
+ x=2+5 7
- x=5-2 3
* x=2*5 10
/ x = 5/2 2.5
% x = 5%2 1
INTERACTIVITY
01.06 Operators and Expressions WITH JAVASCRIPT

More Operators
Operator Example Value stored in x
x = 5; 6
++
x++;
x = 12; 11
--
x--
x = 2; 7
+=
x+=5
INTERACTIVITY
01.06 Operators and Expressions WITH JAVASCRIPT

String Operators

Operator Example Value stored in x


+ x = “Hi” + “There” “HiThere”
+ x = “Hi” + 5 “Hi5”
x = “Hi”
+=
x +=“There” “HiThere”
INTERACTIVITY
01.06 Operators and Expressions WITH JAVASCRIPT

Boolean Operators
• We can also use operators to compare values
• Assume x = 12;
Operator Example Returns
== x ==5 false
== x ==12 true
!= x !=5 true
INTERACTIVITY
01.06 Operators and Expressions WITH JAVASCRIPT

Boolean Operators
• Assume x = 12;

Operator Example Returns


> x >12 false
>= x >=12 true
< x <12 false
<= x <=12 true
INTERACTIVITY
01.06 Operators and Expressions WITH JAVASCRIPT

Boolean Operators
• Assume x = 12;
Operator Example Returns…
== x == “12” true
=== x === “12” false
!=== x !== 12 false

• You need to really stop and think about these


operators…
INTERACTIVITY
01.06 Operators and Expressions WITH JAVASCRIPT

Logical Operators
• Assume x = 12;
Operator Example returns…
(15 > x) && (x > 5) true
&&
both sides must be true
(15 > x) || (x > 5) true
||
at least one side must be true
! !(x == 12) false
INTERACTIVITY
01.06 Operators and Expressions WITH JAVASCRIPT

Review
• Programming is not just about knowing
the syntax of a language
• You need to think about the logic behind
what you want to do, before you start to
code
INTERACTIVITY
01.06 Operators and Expressions WITH JAVASCRIPT

Acknowledgements/Contributions
These slides are Copyright 2015- Colleen van Lent as part of
http://www.intro-webdesign.com/ and made available under a Creative
Commons Attribution Non-Commercial 4.0 License. Please maintain
this last slide in all copies of the document to comply with the attribution
requirements of the license. If you make a change, feel free to add
your name and organization to the list of contributors on this page as
you republish the materials.

Initial Development: Colleen van Lent , University of Michigan School of


Information

You might also like