var p = 'val';
(function () {
if (typeof p === 'undefined' /*Почему он undefined?*/) {
console.log(p);
var p = "newVal";
console.log(p);
} else {
console.log(p);
}
})();// newVal
var p = 'val';
(function () {
var name; // undefined
if (typeof name === 'undefined') {
console.log(name);
name = "newVal";
console.log(name);
} else {
console.log(name);
}
})();// newVal