sass-site icon indicating copy to clipboard operation
sass-site copied to clipboard

Sass: Variables (Documentation)

Open aiman99aleryany opened this issue 3 years ago • 2 comments

I am not sure if I should write this issue here, but here we go! image as you see in this picture from the documentation of sass here about the variables. It says that flow control statements can't create/declare new variables, which is not true

@if 1 {
 $index: 20px;
 @debug $index;
}
@for $i from 1 through 4 {
  $index: 20px;
  @debug $index;
}

In both cases above, the variables are declared and debugged without prompting any errors, as long as I am using the variables inside the flow control.. maybe you should specify that in the documentation because it creates some confusion for beginners like me. have a great day!

aiman99aleryany avatar Sep 11 '22 22:09 aiman99aleryany

.. but they can't declare new variables there.

the key word is "there" -- in the outer scope, not that they can't declare variables at all. They sure can within their inner scope, which is what your code perfectly depicts. In order to change a "global" or "outer scope" variable it needs to exist *there first.

$index: 10px;
@debug $index; // 10px

@if 1 {
 $index: 20px;
}
@debug $index; // 20px

WebMechanic avatar Sep 13 '22 17:09 WebMechanic

@WebMechanic Thank you for your kind reply.. I understand what it meant now, if they could make it clearer in the documentation to the Non-native English speakers. By specifying that *there keyword references the global scope. Thanks in advance.

aiman99aleryany avatar Sep 13 '22 17:09 aiman99aleryany