SASS Equality Operators (original) (raw)

Last Updated : 4 Apr, 2023

Compatibility: Dart Sass is fully compatible with using equality operators, whereas LibSass and older versions of Ruby Sass (older than version 4.0.0) consider numbers as equal even if they have different units or if one has a unit and the other does not. This behavior was not useful and hence the newer versions have removed this as it violates transitivity. The equality operator tells whether the two values are equal or not.

Syntax: == The returned output for this shows whether the two expressions are equal, and != The returned output for this shows whether the two expressions are not equal. Two expressions are said to be equal if they have the same values and same types, this means different for different types shown below:

Example:

css `

@debug 2px == 2px

`

Output:

true

css `

@debug 1px == 1em

`

Output:

false

css `

@debug 96px == 1in

`

Output:

true

Example:

css `

@debug geeksforgeeks == "geeksforgeeks"

`

Output:

true

css `

@debug geeksforgeeks == GFG

`

Output:

false

Example:

css `

@debug hsl(120, 72%, 80%) == #1ba61b

`

Output:

true

css `

@debug rgba(120. 236, 135, 0.1) == rgba(120, 236, 135, 0.5)

`

Output:

false

Example:

css `

@debug (2, 4, 6) == (2, 4, 6)

`

Output:

true

css `

@debug (2 4 6) == (2, 4, 6)

`

Output:

false

css `

@debug (2 4 6) == [2 4 6]

`

Output:

false

Example:

css `

$gradient: ("green" : abc, "cyan" : def)

`

Output:

true

css `

@debug $gradient == ("green" : abc, "blue" : ghi)

`

Output:

true

Example:

css `

@debug true == true

`

Output:

true

css `

@debug false == null

`

Output:

false

Example:

css `

@debug solve(24) == solve(24)

`

Output:

true

css `

@debug solve(24) == solve("geeksforgeeks")

`

Output:

false