Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default argument and "?" is == not === #2653

Closed
ssjr opened this issue Dec 30, 2012 · 3 comments
Closed

Default argument and "?" is == not === #2653

ssjr opened this issue Dec 30, 2012 · 3 comments

Comments

@ssjr
Copy link

ssjr commented Dec 30, 2012

When I use the default arguments or one ? to check a variable, is compiled into == or !=, not === or !==

eg:

"use strict"

product = (title = "product") ->
  title

item = (title) ->
  if title?
    console.log "title is not null"
  unless title?
    title = "item"
  else
    title.replace /\s+/, '-'
  title

results:

// Generated by CoffeeScript 1.4.0
(function() {
  "use strict";

  var item, product;

  product = function(title) {
    if (title == null) {
      title = "product";
    }
    return title;
  };

  item = function(title) {
    if (title != null) {
      console.log("title is not null");
    }
    if (title == null) {
      title = "item";
    } else {
      title.replace(/\s+/, '-');
    }
    return title;
  };

}).call(this);

"Because the == operator frequently causes undesirable coercion, is intransitive, and has a different meaning than in other languages" - http://coffeescript.org/#operators

@vendethiel
Copy link
Collaborator

Because it's checking for null ...

@michaelficarra
Copy link
Collaborator

See my comment in #1631 (comment)

@ssjr
Copy link
Author

ssjr commented Dec 31, 2012

didn't know that. thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants