App Lab Documentation

Inequality operator

Category:Math

Your apps will sometimes need to check if the values in their code are not equivalent, and then possibly perform some specific action using an if, if-else, or while block. == returns true if the value on the left-hand side of the operator is not equal to the value on the right-hand side of the operator.

Examples

Example: Basic inequality check

// Basic numeric inequality check.
var x = 5;
var y = 4;
console.log(x != 5);
console.log(x != y);

Example: "Alan Turing" inequals "ALAN TURING"?

Example: "Alan Turing" inequals "ALAN TURING"? Basic string inequality check. Case matters for string comparison.

// Basic string inequality check. Case matters for string comparison.
var x = "Alan Turing";
var y = "ALAN TURING";
console.log(x != "Alan Turing");
console.log(x != y);

Example: 5 equals "5"?

Example: 5 equals "5"? Numeric string to number conversion is automatic in App Lab.

// Numeric string to number conversion is automatic in App Lab.
var x = 5;
var y = "5";
if(x != y)
{
  console.log("equivalent")
}
else
{
  console.log("not equivalent")
}

Example: 5 equals "five"?

Example: 5 equals "five"? Word string to number conversion is not automatic in App Lab.

// Word string to number conversion is not automatic in App Lab.
var x = 5;
var y = "five";
if(x != y)
{
  console.log("equivalent")
}
else
{
  console.log("not equivalent")
}

Syntax

__ != __

Parameters

NameTypeRequired?Description
___any

The operands can be a number/string/boolean, or a variable containing a number/string/boolean, or the number/string/boolean returned by a function, or the number/string/boolean result of the evaluation of an expression.

Returns

Boolean true or false

Tips

  • JavaScript will automatically perform type conversion for you when comparing two values (e.g. the integer 5 will register as equivalent to the string "5").
  • Comparison operators include < <= == > >= !=

Found a bug in the documentation? Let us know at support@code.org.