JavaScript Operators Overview

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What will the output of the following code be: document.write("Sum: " + (a+b)); if a = 2 and b = 5?

  • Sum: 7 (correct)
  • Sum: 12
  • Sum: 5
  • Sum: 10

Which operator is used to assign a value to a variable in JavaScript?

  • = (correct)
  • ===
  • ==
  • !=

What is the significance of the '===' operator compared to '=='?

  • It checks if values are equal, ignoring data type.
  • It checks if values and data types are both equal. (correct)
  • It checks if values are not equal, ignoring data type.
  • It checks only the data type of the values.

If variable e is defined as var e = (75 == 100), what will be the value of e?

<p>False (C)</p> Signup and view all the answers

What does the '!==' operator do in JavaScript?

<p>Checks if two values are not equal, considering data type. (D)</p> Signup and view all the answers

Why is the String Operator (+) important in JavaScript?

<p>It links two or more string values together. (A)</p> Signup and view all the answers

In an if statement, what happens if the condition is false?

<p>The else block executes. (C)</p> Signup and view all the answers

What will the output of document.write(!(e)); be if e is false?

<p>True (B)</p> Signup and view all the answers

Signup and view all the answers

Flashcards

Operator

A special symbol in JavaScript used to perform operations on values.

Arithmetic Operator

Used to perform mathematical operations like addition, subtraction, multiplication, etc.

Assignment Operator

Used to assign values to variables.

Comparison Operator

Compare two values and return a boolean result (true or false).

Signup and view all the flashcards

String Operator

Links two or more string values together. Used with the '+' symbol.

Signup and view all the flashcards

If statement

Executes a block of code if a condition is true.

Signup and view all the flashcards

Else statement

Executes a block of code if the condition in the 'if' statement is false.

Signup and view all the flashcards

Loop

A block of code that can be executed repeatedly, often depending on a condition. It is used to loop through arrays and objects, processing each element.

Signup and view all the flashcards

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
  • Assignment Operators: Used to assign values to variables.
    • Example: a = 7, a += 1 (equivalent to a = a + 1), a -= 3 (equivalent to a = a - 3), a *= 4 (equivalent to a = a * 4), a /= 3 (equivalent to a = a / 3), a %= 10 (equivalent to a = a % 10).
  • 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" is true).
    • Note: === and !== strictly consider data types (e.g., 3 === "3" is false).
  • Logical Operators: Compare two or more comparisons and return a boolean result.
    • && (and), || (or), ! (not).
    • Example: (16 == "16") && ("car" != "caR") is true.
  • String Operator: Used to link two or more string values together.
    • Example: "My name is " + "Miguel" results in "My name is Miguel".

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 the if condition is false.
    • Example flowchart shown.
  • else if statement: Specifies a new condition if the previous if or else 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.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser