Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

CoffeeScript Gets Strict Mode

DZone's Guide to

CoffeeScript Gets Strict Mode

· Web Dev Zone
Free Resource

Learn how to build modern digital experience apps with Crafter CMS. Download this eBook now. Brought to you in partnership with Crafter Software

What's strict mode? And more importantly, how does it work in CoffeeScript 1.3.x?

Mozilla Developer Network (MDN) defines ECMAScript 5 strict mode as "a way to opt in to a restricted variant of JavaScript." It basically provides a syntax error system to prevent you from creating trouble with JavaScript in a number of areas, ranging from the commonplace (global variable leaks) to the arcane (numeric octal literals). It also signals security issues. For further reading about strict mode and JavaScript, check out John Resig's post on strict mode.


C offeeScript already does quite a bit to guard us from JavaScript pitfalls, so what additional help do we get from strict mode? Alex MacCaw has written this up nicely in the "Strict mode" section of  The Little Book on CoffeeScript, Chapter 7, The Bad Parts .

For the final word on the feature, read the CoffeeScript project issue on GitHub. Jeremy Ashkenas' comment on the issue is noteworthy: " I think if we do this, we enforce our static strict mode restrictions everywhere, but we do not put any "use strict"directives into your code for you." In other words, the CoffeeScript compiler does the strict mode syntax checks itself, at compile time. This is good. You don't want to wait until you run the generated JavaScript output to discover your errors.

Crafter is a modern CMS platform for building modern websites and content-rich digital experiences. Download this eBook now. Brought to you in partnership with Crafter Software.

Topics:

Published at DZone with permission of Chris Smith, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}