Block Scope in ES6

let's get it started!

Marek Stępień

Who's doin' the talkin'?

ECMAScript 5

Warning!

All of this stuff is pretty bleeding-edge, not yet accepted by ECMA/TC-39. Everything can change and look totally different in the final ES6 spec. :-)

ECMAScript 6 „Harmony”

ES6 support in Firefox

~ = differences with the final spec highly probable

Opt-in for the new syntax in Fx

Some ES6 features have a syntax that is incompatible with older JS versions, so ES6 code has to be marked in a special way. To get all the features in current Firefoxes:

<script type="application/javascript;version=1.8">
let x = 5;
</script>

The final standard will surely differ here ("application/ecmascript;version=6"?)

ES6 stuff not needing new syntax can work without this type attribute.

Scope in JS (ES3) - how it's been

What will c0nsole.write show? why?
Know the answer? NOT SO FAST! Let others think about this for a while, too! :)

Scope in JS (ES3) - how it's been

Scope in JS (ES3) - how it's been

Scope in JS (ES3) - how it's been

Problem with var

Old solution: closure

ES5 solution: bound function

ES3: crazy evil trick with throw

TEH EVILZ! Don't use it. EVER!

ES6: let the sunshine in :)

Three variants of let

let definition

let statement

let expression

let expression

Where to play with let?

const - constant definitions

ES6 says const introduces the constant in a block scope. Currently in Firefox it introduces the constant in function scope (like var) Bug 611388

Thank you!

Questions?

Slides powered by: CSSS by Lea Verou + marcoos' CSSS-Plugins (MIT License)

Background: untitled by John Wilson (Flickr: johnwilson1969; CC-BY-SA)

Hoisting example blatantly stolen from adequatelygood.com.
Evil crazy throw trick originally discovered by danbeam.org.