Skip to content
Junior–Senior166 views

Investigation of variable lifting in an immediately invoked function

Task condition

Analyze how hoisting occurs for the variable name inside the IIFE, and predict what text will appear in the console.

var name = 'Коля!';

(function () {
    if (typeof name === 'undefined') {
        var name = 'Вася';
        console.log('Пока, ' + name);
    } else {
        console.log('Привет, ' + name);
    }
})();
Frontend tasks in the code trainer