Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

116
Visualizações
Changing the value of a variable from the scope of the function

I am studying and trying to understand how scope works in javascript. My main problem is that when I change the value of a variable using a function, it gives me not what I want. I expect to receive in console last scope, like in function visible_scope_1();. but as for the last function visible_scope_3(), I just wanted to do it a little differently, but I also got a failure. In general, you may not pay attention to the last function.

// Very well ! So and want ...
// only do with help at scope visible functions ...
function visible_scope_1() {
    var message = "local scope";
    message = "changed local scope";
    message = "last scope";
    return message;
}

// Wrong : show all resuls ...
function visible_scope_2 () {
    var message = "local scope";
    var a1 = function() {
        console.log(message = "inside local scope");
        var b2 = function () {
            console.log(message = "deeper scope");
            var c3 = function () {

                // I want to get the result from this scope. Is it possible?
                console.log(message = "last scope");
            }; c3();
        }; b2();
    }; a1();
}

// Wrong : show undefined
function visible_scope_3 () {
    message = "local scope";
    var a1 = function() {
        message = "inside local scope";
        return message;
        var b2 = function () {
            message = "deeper scope";
            return message;
            var c3 = function () {
                // i expect to show in console "last scope"
                message = "last scope";
                return message;
            }; c3();
        }; b2();
    }; a1();
}

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda