Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!