Js Operators
Js Operators
Outline
<script>
Variables
Operators
2
Dr. Navneet Kaur, Lovely
Professional University
<script>
The <script> HTML element is used to embed executable
code or data; this is typically used to embed or refer to
JavaScript code.
<head>
<script>
. . .
</script>
</head>
3
Dr. Navneet Kaur, Lovely
Professional University
<script>
<head>
<script src="javascript.js">
. . .
</script>
</head>
4
Dr. Navneet Kaur, Lovely
Professional University
Variables
A variable is a container for a value, like a number we might
use in a sum, or a string that we might use as part of a
sentence.
Operators
Arithmetic operators
Assignment operators
Comparison operators
Logical operators
String operators
Conditional (ternary) operator
6
Dr. Navneet Kaur, Lovely
Professional University
Arithmetic Operators
Remainder (%)
Increment (++)
Decrement (--)
Unary negation (-)
Unary plus (+)
Exponentiation operator (**)
7
Dr. Navneet Kaur, Lovely
Professional University
Assignment Operators
Shorthand
Name Meaning
operator
Assignment x = f() x = f()
Comparison Operators
Examples returning
Operator Description
true
3 == var1
Returns true if the operands
Equal (==) "3" == var1
are equal.
3 == '3'
Returns true if the operands var1 != 4
Not equal (!=)
are not equal. var2 != "3"
Comparison Operators
Examples returning
Operator Description
true
Returns true if the left operand is var2 > var1
Greater than (>)
greater than the right operand. "12" > 2
Returns true if the left operand is
Greater than or var2 >= var1
greater than or equal to the right
equal (>=) var1 >= 3
operand.
Less than or Returns true if the left operand is less var1 <= var2
equal (<=) than or equal to the right operand. var2 <= 5
10
Dr. Navneet Kaur, Lovely
Professional University
Logical operators
Logical operators are typically used with Boolean (logical)
values.
Logical AND (&&) -> expr1 && expr2
Logical OR (||) -> expr1 || expr2
Logical NOT (!) -> !expr
11
Dr. Navneet Kaur, Lovely
Professional University
String operators
The concatenation operator (+) concatenates two string
values together, returning another string that is the union of
the two operand strings.
Thank you