Reputation: 8936
My codes:
['nl', 'fr', 'de'].forEach(function(arrElement) {
const var1 = 'var1';
describe(arrElement + ' suite', function() {
const var2 = 'var2';
it('This thing should behave like this', function(done) {
const var3 = 'var3';
foo.should.be.a.String();
done();
});
});
});
In the above codes, the describe
block will run three times. There are three variables: var1, var2, var3. During the three runs, which variable will be created only once? which variable will be created three times?
Thanks
Upvotes: 0
Views: 182
Reputation: 887215
forEach()
calls its callback once per array element.
Therefore, your function (and all of its variables and code) will run three times.
Local variables are never shared across multiple calls to their containing function.
Upvotes: 1