JavaScript Operators

Last Updated :
Discuss
Comments

Question 1

Given the following code:

JavaScript
console.log(foo());
var foo = function() {
  return "Function Expression";
};
function foo() {
  return "Function Declaration";
}

What will be logged to the console?

  • A

    Function Expression

  • B

    Function Declaration

  • C

    TypeError

  • D

    ReferenceError

Question 2

What will be the output of the following JavaScript code?

JavaScript
let a = 1;

function outer() {
  console.log(a);
  let a = 2;
}

outer();


  • A

    1

  • B

    2

  • C

    undefined

  • D

    ReferenceError

Question 3

What will be the result of the following operation?

JavaScript
console.log(5 % 2);


  • A

    1

  • B

    2

  • C

    1.5

  • D

    5

Question 4

Which operator is used to compare both value and type?

  • A

    ==

  • B

    ===

  • C

    !=

  • D

    =

Question 5

Which of the following is a logical AND operator?


  • A

    &&

  • B

    ||

  • C

    !

  • D

    ^^

Question 6

Which of the following operators is used to assign a value to a variable?

  • A

    ==

  • B

    ===

  • C

    =

  • D

    :=

Question 7

Find the output of the following.

for (var i = 0; i < 3; i++) {

setTimeout(function() {

console.log(i); }, 100);

}

  • A

    ReferenceError

  • B

    3 3 3

  • C

    0 1 2

  • D

    undefined undefined undefined

Question 8

What is the output of this ternary operation?

JavaScript
const value = 10; 
console.log(value > 5 ? "Yes" : "No");


  • A

    Yes

  • B

    No

  • C

    Error

  • D

    Undefined

Question 9

Which operator is used for optional chaining in JavaScript?

  • A

    .?

  • B

    ?.

  • C

    ::

  • D

    ->

Question 10

What will the following code log?

JavaScript
console.log(5 == "5");


  • A

    true

  • B

    false

  • C

    undefined

  • D

    Error

There are 10 questions to complete.

Take a part in the ongoing discussion