Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda