Operators in JavaScript Fundamentals
10 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 is the output of the following code snippet: console.log(5 < 10)?

  • 5
  • 10
  • true (correct)
  • false
  • What does the following code snippet output: console.log(3 > 5 || 0)?

  • 5
  • 0
  • true (correct)
  • 3
  • In JavaScript, what would be the result of console.log(5 === '5')?

  • '5'
  • false (correct)
  • true
  • Syntax Error
  • What is the final value of a after executing the code: let a = 5; a++; ++a; a--?

    <p>7</p> Signup and view all the answers

    What is the output of console.log(!(5 > 3))?

    <p>'false'</p> Signup and view all the answers

    What would be the result of console.log(1 == true)?

    <p>'Syntax Error'</p> Signup and view all the answers

    Given a = 2, what does console.log(a++ - --a) output?

    <p>-2</p> Signup and view all the answers

    What will be the output of console.log((4 + 2) * 3)?

    <p>'18'</p> Signup and view all the answers

    For console.log(!(0 && true)), what would be the output?

    <p>'true'</p> Signup and view all the answers

    If let x = 5, what will be the result of console.log(x += x - x++)?

    <p>'0'</p> Signup and view all the answers

    Study Notes

    Prefix Increment and Decrement Operators

    • The operator is placed before the variable, and the value of the variable is incremented or decremented before it is used.
    • Example: let a = 10; console.log(++a); // 11 and let a = 10; console.log(--a); // 9

    Postfix Increment and Decrement Operators

    • The operator is placed after the variable, and the value of the variable is used before it is incremented or decremented.
    • Example: let a = 10; console.log(a++); // 10 and let a = 10; console.log(a--); // 10

    Comparison Operators

    • Comparison operators compare two values and return a Boolean value: either true or false.
    • They are useful in decision-making and loop programs in JavaScript.

    Arithmetic Operators

    • Addition: let sum = 5 + 3; console.log(sum); // 8
    • Subtraction: let difference = 10 - 4; console.log(difference); // 6
    • Multiplication: let product = 2 * 6; console.log(product); // 12
    • Division: let quotient = 15 / 3; console.log(quotient); // 5
    • Remainder (Modulus): let remainder = 17 % 4; console.log(remainder); // 1
    • Exponentiation: let result = 2 ** 4; console.log(result); // 16

    Assignment Operator

    • Assignment operators are used to assign values to variables.
    • The = sign is used for assignment.
    • Examples:
      • Addition assignment: x += 3;
      • Subtraction assignment: x -= 2;
      • Multiplication assignment: x *= 4;
      • Division assignment: x /= 3;
      • Remainder (Modulus) assignment: x %= 5;
      • Exponentiation assignment: x **= 2;

    Logical Operators

    • Logical OR: true || true; // true, true || false; // true, false || true; // true, false || false; // false
    • Logical NOT: ! converts the operator to Boolean and returns a flipped value.
    • Example: let Yes = true; let No = false; console.log(!Yes); // false, console.log(!No); // true

    Operator Precedence

    • Operator precedence determines the order in which operators are parsed concerning each other.
    • Example: let result = 2 + 3 * 4; console.log(result); // 14
    • The order of operations is determined by the operator's precedence value.

    Operator Associativity

    • Operator associativity defines the order in which operators of the same precedence are evaluated.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Description

    Learn about the prefix and postfix increment and decrement operators in JavaScript. Understand how these operators behave before and after the variable. Practice examples to see the effects of using these operators.

    More Like This

    Use Quizgecko on...
    Browser
    Browser