Why doesn't SASS have local variables?

Just switched from LESS and found that in SASS all the variables are global. And so, to define a special variable for a particular block, I need to write something like $words-that-describe-particular-block-padding: 10px; .

In all reviews, the authors made CASS more advanced than LESS because of its versatility, but in fact the absence of such a simple thing as namespacing kills the whole experience with it.

Why was this design decision made?
I am mistaken, and global variables are better because I am missing?

UPD:
SASS:

 $var: 1px; #id1 { $var: 2px; width: $var; } #id2 { width: $var; } 

LESS:

 @var: 1px; #id1 { @var: 2px; width: @var; } #id2 { width: @var; } 

Try examples with these online compilers:

+4
source share
1 answer

This is not entirely true. If you run the following code:

 .header { $color: #000; background: $color; } .footer { background: $color; } 

You'll get

 Sass Error: Undefined variable: "$color". 

So, the color variable is not global at all. It is available only in the context of its definition.

However, SASS or LESS have many limitations. If you are not happy with what they offer, I suggest checking it out .

+13
source

All Articles