Scope of a variable in JavaScript