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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:53:43+00:00 2026-05-27T06:53:43+00:00

If I pass a variable to the existential operator in Coffescript it is converted

  • 0

If I pass a variable to the existential operator in Coffescript it is converted to a pair of !== comparisons:

            compiles to
Coffeescript ------> JS
a?                   typeof a !== "undefined" && a !== null;

But if I use a literal or expression it instead uses a != comparison:

            compiles to
Coffeescript ------> JS
17?                  17 != null;

//same thing for regexps, strings, function calls and other expressions
//as far as I know.

Is there any reason for preferring the double !==s over the shorter != null, other then perhaps making JSLint happy?

  • 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-27T06:53:44+00:00Added an answer on May 27, 2026 at 6:53 am

    Short answer: They’re behaviorally equivalent, and the != null compilation is an optimization. Either way, x? means that x is neither null nor undefined.

    People ask about this a lot on the CoffeeScript issue tracker. The reason x != null isn’t used everywhere as the compiled output of x? is that x != null (or any other comparison against x) causes a runtime error if x doesn’t exist. Try it on the Node REPL:

    > x != null
    ReferenceError: x is not defined
    

    By “doesn’t exist,” I mean no var x, no window.x = ..., and you’re not in a function where x is the name of an argument. (The CoffeeScript compiler can’t identify the window.x case because it doesn’t make any assumptions about the environment you’re in.) So unless there’s a var x declaration or an argument named x in the current scope, the compiler has to use typeof x !== "undefined" to prevent your process from potentially crashing.

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

Sidebar

Related Questions

I would like to pass a variable to the binary operator $. Let's say
I want to pass variable arguments obtained in one function to other function but
I want to pass value of a variable from template to a templatetag but
I'm trying to pass a variable to nawk in a bash script, but it's
I'm trying to pass a variable 'edit_id' to a load string but it doesn't
Its kinda dummy question, but how to pass variable from one button click function
how to pass variable from zf to javascript/jquery? thanks
How can I pass a variable number of args to a yield. I don't
I want to pass a variable to a UIButton action, for example NSString *string=@one;
How can I pass a variable value from a template using JavaScript without 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.