232k views
0 votes
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;

User Foggzilla
by
5.6k points

1 Answer

6 votes

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;

Step-by-step 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.

User Hackwithharsha
by
4.9k points