1
Dr. Navneet Kaur, Lovely
Professional University
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.
var name = “Manish”;
or
let name = “Manish”;
or
const name = “Manish”;
5
Dr. Navneet Kaur, Lovely
Professional University
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()
Addition assignment x += f() x = x + f()
Subtraction assignment x -= f() x = x - f()
Multiplication assignment x *= f() x = x * f()
Division assignment x /= f() x = x / f()
Remainder assignment x %= f() x = x % f()
8
Dr. Navneet Kaur, Lovely
Professional University
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"
Returns true if the operands
Strict equal (===) are equal and of the same 3 === var1
type.
Returns true if the operands
Strict not equal (! var1 !== "3"
are of the same type but not
==) 3 !== '3'
equal, or are of different type.
9
Dr. Navneet Kaur, Lovely
Professional University
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.
Returns true if the left operand is less var1 < var2
Less than (<)
than the right operand. "2" < 12
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.
console.log("my " + "string");
12
Dr. Navneet Kaur, Lovely
Professional University
Conditional (ternary) operator
The conditional operator is the only JavaScript operator that
takes three operands. The operator can have one of two
values based on a condition.
condition ? val1 : val2
const status = age >= 18 ? "adult" : "minor";
13
Dr. Navneet Kaur, Lovely Profession
al University
Thank you