Podcast
Questions and Answers
What will the output of the following code be: document.write("Sum: " + (a+b)); if a = 2 and b = 5?
What will the output of the following code be: document.write("Sum: " + (a+b)); if a = 2 and b = 5?
Which operator is used to assign a value to a variable in JavaScript?
Which operator is used to assign a value to a variable in JavaScript?
What is the significance of the '===' operator compared to '=='?
What is the significance of the '===' operator compared to '=='?
If variable e is defined as var e = (75 == 100), what will be the value of e?
If variable e is defined as var e = (75 == 100), what will be the value of e?
Signup and view all the answers
What does the '!==' operator do in JavaScript?
What does the '!==' operator do in JavaScript?
Signup and view all the answers
Why is the String Operator (+) important in JavaScript?
Why is the String Operator (+) important in JavaScript?
Signup and view all the answers
In an if statement, what happens if the condition is false?
In an if statement, what happens if the condition is false?
Signup and view all the answers
What will the output of document.write(!(e)); be if e is false?
What will the output of document.write(!(e)); be if e is false?
Signup and view all the answers
Signup and view all the answers
Study Notes
JavaScript Operators
- Operators are special symbols that perform operations on variables and values.
-
Arithmetic Operators: Used for mathematical operations (addition, subtraction, multiplication, division, modulus, exponentiation).
- Example:
5 + 2 = 7
,4 - 2 = 2
,2 * 3 = 6
,4 / 2 = 2
,5 % 2 = 1
,4 ** 2 = 16
- Example:
-
Assignment Operators: Used to assign values to variables.
- Example:
a = 7
,a += 1
(equivalent toa = a + 1
),a -= 3
(equivalent toa = a - 3
),a *= 4
(equivalent toa = a * 4
),a /= 3
(equivalent toa = a / 3
),a %= 10
(equivalent toa = a % 10
).
- Example:
-
Comparison Operators: Compare two values/variables and return a boolean result (true or false).
-
==
(equal to),===
(strictly equal to),!=
(not equal to),!==
(strictly not equal to),>
(greater than),<
(less than),>=
(greater than or equal to),<=
(less than or equal to). - Note:
==
and!=
do not consider data types (e.g.,3 == "3"
istrue
). - Note:
===
and!==
strictly consider data types (e.g.,3 === "3"
isfalse
).
-
-
Logical Operators: Compare two or more comparisons and return a boolean result.
-
&&
(and),||
(or),!
(not). - Example:
(16 == "16") && ("car" != "caR")
istrue
.
-
-
String Operator: Used to link two or more string values together.
- Example:
"My name is " + "Miguel"
results in"My name is Miguel"
.
- Example:
JavaScript Conditional Statements
-
if
statement: Executes a block of code if a condition is true.- Example flowchart shown.
-
else
statement: Executes a block of code if theif
condition is false.- Example flowchart shown.
-
else if
statement: Specifies a new condition if the previousif
orelse if
conditions are false.- Example flowchart shown.
Additional JavaScript Methods
-
confirm()
: Displays a dialog box asking the user to verify an action with "Yes" or "No." -
prompt()
: Displays a dialog box asking the user to input a value.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
This quiz focuses on JavaScript operators, including arithmetic, assignment, and comparison operators. You'll learn how these operators work and see examples of their usage in coding. Test your understanding and enhance your JavaScript skills today!