Bird
0
0

Which of the following is the correct syntax to check if variable a is not equal to variable b in Ruby?

easy📝 Syntax Q12 of 15
Ruby - Operators and Expressions
Which of the following is the correct syntax to check if variable a is not equal to variable b in Ruby?
A<code>a !== b</code>
B<code>a =! b</code>
C<code>a <> b</code>
D<code>a != b</code>
Step-by-Step Solution
Solution:
  1. Step 1: Recall Ruby's not equal operator

    Ruby uses != to check if two values are not equal.
  2. Step 2: Check each option's syntax

    a != b is correct. a =! b is invalid syntax. a <> b is not Ruby syntax. a !== b is JavaScript syntax, not Ruby.
  3. Final Answer:

    a != b -> Option D
  4. Quick Check:

    Not equal operator = != [OK]
Quick Trick: Not equal in Ruby is !=, not =! or !== [OK]
Common Mistakes:
  • Using =! instead of !=
  • Using !== which is JavaScript, not Ruby
  • Using <> which is invalid in Ruby

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes