Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3392230
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:53:46+00:00 2026-05-18T03:53:46+00:00

var x = 5; function f(y){ return (x+y)-2 }; function g(h){ var x =

  • 0
var  x  =  5;
function f(y){ return (x+y)-2 }; 
function g(h){ var x = 7; return h(x) }; 
{ var x=10; z=g(f) };

I’m working through some problems from my textbook in my class to prepare for our next exam, and can’t figure out how the above evaluates.

Mostly, I don’t understand the call z=g(f), as when f is evaluated, it isn’t provided an argument, so how does it evaluate at all? How does it know what y is?

Also, as far as scoping goes, I believe javascript treats most everything as global variables, so the last x that is set would be the x value used in function f, correct?

Thanks for any help!

Please note, these are extra problems in the back of the book I’m practicing to prepare for the exam, these are not direct homework questions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:53:47+00:00Added an answer on May 18, 2026 at 3:53 am
    var  x  =  5;
    function f(y){ return (x+y)-2 }; 
    function g(h){ var x = 7; return h(x) }; 
    
    { var x=10; z=g(f) };
    

    This sets the global x to 5, then (before any function calls) 10. The braces don’t create a new scope.

    You pass f into the g function (it becomes formal parameter h). That is then called with x == 7 (g is a function with its own scope, so this x shadows the global).

    Entering f, x becomes the formal parameter y; y is thus 7. (x + y) - 2 is then 10 + 7 - 2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

JavaScript does funky automatic conversions with objects: var o = {toString: function() {return 40;
I am manually creating the equivalent lambda: var function = p => p.Child.Any(c =>
I have this piece of code: $(#faq).click(function () { var url = $.get(faq, {
I have this function in my head: <head> window.onload = function(){ var x =
I have put together the following mootools script window.addEvent('domready', function() { var shouts =
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} What's the
Could anyone explain me why: function doAjax() { var xmlHttpReq = false; try {
View this code: function testprecision(){ var isNotNumber = parseFloat('1.3').toPrecision(6); alert(typeof isNotNumber); //=> string }
I have this piece of code: var myObj = function () { this.complex =
I'm working through R Murphy's JQuery Fundamentals and am trying to make sense of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.