I run this Sass code:
$a: 1;
@if 2 + 2 == 4 {
$a: 2;
}
@debug $a;
I expect to see 2. The output, however, is:
Line 5 DEBUG: 1
I understand that Sass creates a new $a
variable inside the @if
scope. How can I change this behaviour and assign a value to the global $a
?
I use Sass 3.4.0.
As you're using Sass 3.4+, you should append the
!global
flag to your variable declaration:The original SASS_REFERENCE on variable declaration stated:
but the SASS_CHANGELOG of 3.4+ shows that this behaviour has changed:
By trial-and-error, I found a solution: I have to add
!global
in the assignment.