JSOperators_Quiz.md - brainchildservices/curriculum GitHub Wiki

Quiz

1. What is Operators?

  • A: In JavaScript, an operator is a special symbol used to perform operations on operands (values and variables). For example,

    2 + 3; // 5
    

2. Different Types of JavaScript Operator?

  • A:
    • Assignment Operators
    • Arithmetic Operators
    • Comparison Operators
    • Logical Operators
    • Bitwise Operators
    • String Operators
    • Other Operators

3. Use of Assignment Operators?

  • A: Assignment operators are used to assign values to variables. For example,

    const x = 5;
    

4. Use of JavaScript Arithmetic Operators?

  • A: Arithmetic operators are used to perform arithmetic calculations. For example,

    const number = 3 + 5; // output :- 8
    

5. Use of JavaScript Comparison Operators?

  • A: Comparison operators compare two values and return a boolean value, either true or false. For example,

    const a = 5, b = 2;
    console.log(a>b); //True
    

6. Use of JavaScript Logical Operators?

  • A: Logical operators perform logical operations and return a boolean value, either true or false. For example,

    const x = 5, y = 3;
    (x < 6) && (y < 5); // true
    

Here, && is the logical operator AND. Since both x < 6 and y < 5 are true, the result is true.

7. Use of JavaScript Bitwise Operators?

  • A: Bitwise operators perform operations on binary representations of numbers. Bitwise operators are rarely used in everyday programming.

8. Use of JavaScript String Operators?

  • A: In JavaScript, you can also use the + operator to concatenate (join) two or more strings.

    // concatenation operator
    console.log('hello' + 'world');
    
    let a = 'JavaScript';
    
    a += ' tutorial';  // a = a + ' tutorial';
    console.log(a);
    

9. which are the Other JavaScript Operators?

  • A: other operators available in JavaScript.
    • , - Evaluates multiple operands and returns the value of the last operand. For example,

      let a = (1,3,4)  // output 4
      
    • ?: - Return Value Based on the condition. For example,

      (5, 3) 'success' : 'error' ; // Output: success
      
    • delete - Deletes an object Property, or an element of an array. for Example,

      delete x
      
    • typeof - Returns a string indicating the datatype. For example,

      typeof 3;  //Output "number"
      
    • Void - Discards the expression's return value. For example,

      Void(x)
      
    • in - returns true if the specified property in the object. For example,

      prop in object
      
    • instanceof - Returns true if the specified object is of the specified object type. For Example,

      object instanceof object_type