1.

Which of the following JavaScript statement is to compare if num is 2 or 5, if yes, increment num by 1?

if( num==2 || 5)
num = num +1;

if( num==2 || num==5)
num = num +1;

if( num=2 || 5)
num = num +1;

if( num==2 || num=5)
num = num +1;

Respuesta :

Answer:

Hi!

The following Javascript statement compares if num is 2 or 5 and increment num by 1 if true.

if ( num==2 || num==5)  

num = num +1;

Explanation:

The operator == is used to compare if the operands are equal.

The operator || is OR.

  • If at least one of the operands is true then return true.
  • If all operands are false returns false.

if( num==2 || num==5) // if num is equal 2 or if num is equal 5

num = num +1; // adds 1 to num.