Perhaps I'm not aware of how
for
i
for
var loopOne = function(test) {
for(i = 0; i < test.length; i++)
console.log(getMask(test));
};
var getMask = function(pass) {
var s = "";
for (i = 0; i < pass.length; i++) {
s = s + "*";
}
return s;
};
loopOne('hello');
*****
i
= 'hello'.length + 1
i
for
for
In Javascript, variables are scoped with the var
keyword. When declaring variables with var
, the variable is scoped to the current function. When assigning to a variable without using the var
keyword, it is assumed you're talking about an already defined variable in the same or a higher scope. If none is found, the variable is created in the highest scope.
Bottom line: declare all your variables using var
.