While experimenting with sass @function
, I made an interesting discovery. When my variable is declared as global scope, the function fails to apply changes to this variable and only returns its initial value. However, when I declare the variable as function scope, the changes are successfully applied to the variable without any issues, resulting in the expected value being returned. This raised the question of why this discrepancy occurs in the first scenario?
code:
//first scenario
$s:8;
@function lome($a...){
@each $i in $a{
$s:$s+$i;
}
@return $s;
}
@debug lome(1,2,3);
//expected output:14;
//output:8;
//second scenario
@function lome($a...){
$s:8;
@each $i in $a{
$s:$s+$i;
}
@return $s;
}
@debug lome(1,2,3);
//expected output:14;
//result:14;