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

Replace or= with ?= #7

Open
liqweed opened this issue Apr 12, 2012 · 2 comments
Open

Replace or= with ?= #7

liqweed opened this issue Apr 12, 2012 · 2 comments

Comments

@liqweed
Copy link

liqweed commented Apr 12, 2012

CoffeeScript 1.3.1 made or= a syntax error. Conditional assignment should be made with the ?= operator.

@fson
Copy link

fson commented May 14, 2012

The change log says "Conditional assignment of previously undefined variables", so it doesn't mean the syntax is depracated, only that the variable must be defined first.

@Zegnat
Copy link

Zegnat commented Jul 21, 2012

Both or= and ?= throw an error in CoffeeScript 1.3.3 unless the variable has been previously defined. This issue should be closed.

@liqweed: Conditional assignment should be made with the ?= operator.

As far as actually replacing or= with ?= is concerned, bear in mind that these two are not synonymous and cannot be swapped without it changing the JavaScript output:

// variable = null
var variable;
variable = null;

// variable ?= 'value'
if (variable == null) {
  variable = 'value';
}

// variable or= 'value'
variable || (variable = 'value');

Note also, and this might be important to some, that ?= will throw a warning when your code is going through JavaScript Lint:

comparisons against null, 0, true, false, or an empty string allowing implicit type conversion (use === or !==)

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

No branches or pull requests

3 participants