JavaScript Operators Overview
9 Questions
0 Views

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</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.</p> Signup and view all the answers

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

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

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

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

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

    <p>True</p> 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
    • 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

    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!

    More Like This

    JavaScript Logical Operators: OR, AND, NOT
    10 questions
    JavaScript Data Types and Operators
    10 questions
    JavaScript Operators Quiz
    5 questions
    JavaScript Basics: Ternary, Switch, and State
    18 questions
    Use Quizgecko on...
    Browser
    Browser