Equal to operator: Difference between revisions
From Coderwiki
More actions
new |
m replace 'conditional operator' with 'comparison operator' |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
One common [[ | One common [[comparison operator]] is the '''equal to operator'''. | ||
This operator will return [[Boolean|true]] if the value on the '''left''' is '''the same as''' the value on the '''right''' of the operator. | This operator will return [[Boolean|true]] if the value on the '''left''' is '''the same as''' the value on the '''right''' of the operator. | ||
== Syntax == | == Syntax == | ||
In most languages, the | In most languages, the equal to operator is represented by a <code>==</code> symbol. This is different from the [[assignment]] [[Assignment operator|operator]], <code>=</code> which is used to set the value of a variable. | ||
== Comparison of different types == | == Comparison of different types == | ||
Latest revision as of 10:26, 9 August 2025
One common comparison operator is the equal to operator.
This operator will return true if the value on the left is the same as the value on the right of the operator.
Syntax
edit edit sourceIn most languages, the equal to operator is represented by a == symbol. This is different from the assignment operator, = which is used to set the value of a variable.
Comparison of different types
edit edit sourceMost programming languages (with the notable exception of JavaScript) will return false if the two values being compared are of a different type.
For example, if we compare the number 5 with the string "5", the result will be false because the values were of different types.
See JavaScript equal to operator for info on how JavaScript handles the equal to operator(s).
Example
edit edit sourceboolean a = 7 == 7; // true
boolean b = 6 == 7; // false
boolean c = 5 == "5"; // false... unless you're using JavaScript!