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 8451091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:08:39+00:00 2026-06-10T11:08:39+00:00

As a new javascript developer, I have spent some time with this code snippit

  • 0

As a new javascript developer, I have spent some time with this code snippit from Chapter 6 of Eloquent Javascript, I am still trying to understand the following code example :

function negate(func) {
  return function(x) {
    return !func(x);
  };
}
var isNotNaN = negate(isNaN);
document.writeln(isNotNaN(NaN));

Where it particular loses me is the following line, I just don’t understand the call in general and where the variable/value for NaN comes from:

document.writeln(isNotNaN(NaN));
  • 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-06-10T11:08:40+00:00Added an answer on June 10, 2026 at 11:08 am

    I think xdazz pretty much covered it, but since you said you still don’t get it maybe it would help to hear the explanation in somebody else’s words.

    This line:

    var isNotNaN = negate(isNaN);
    

    …declares a variable isNotNan that is assigned equal to the result of a call to the negate() function, passing isNan as a parameter.

    That parameter isNan is actually a function as described by MDN, but negate() would accept any function as a parameter, you could say for example var isNotFinite = negate(isFinite);.

    Now the negate() function actually creates and returns another function, so after that line runs isNotNan references that returned function, which means you can call it as isNotNan(someVal).

    So then the line:

    document.writeln(isNotNaN(NaN));
    

    … calls isNotNan() and passes it NaN as a parameter, and the result is written out to the document.

    “I just don’t understand…where the variable/value for NaN comes from”

    NaN is a property of the global object. To oversimplify, it is a constant provided to you by the JS environment.

    Regarding how the negate() function works, it relies on the concept of “closures”, which means that functions declared inside negate() have access to its variables and parameters even after negate() completes. You’ll notice that the returned function references the func parameter. So when you call the returned function via isNotNaN() it can still access that original func parameter that is set to the isNan function.

    The effect is kind of like doing this:

    var isNotNaN = function(x) {
        return !isNan(x);
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Javascript code I inherited from another developer. I am very new
I`m new to JavaScript and I need some help extracting the ID from URL
A JavaScript newbie here. I have this following code: function testObject(elem) { this.test =
from the page https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Details_of_the_Object_Model : When JavaScript sees the new operator, it creates a
I have some Javascript code that acts on an pixel array defined like so:
I'm new to JavaScript and the Google Maps API v3. I'm trying the Developer's
I have this code <title>Welcome</title> <head> <script type=text/javascript> var id = ...; var sessionCount
When creating a new Image element in javascript, Google Chrome's memory tool (Developer tools
I'm relatively new javascript, but I am comfortable in other languages. I'm trying to
New to javascript and such, trying to create a loop for fading logos using

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.