Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine

ECMAScript 2015 / ES6 / Harmony / Cookies

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

Welcome back! Oh man am I super excited about this tutorial. In the first episode, we dug deep into JavaScript: its great features, its weird features, and ultimately, enough good stuff to start getting our code organized.

But, uh, I ignored a gigantic thing in the JavaScript world. I mean, really big, like trying to stay cool when Godzilla is stomping on cars all around you! JavaScript... has a new version... with a ton of new features and significant changes to the language! And guess what? It's not even new anymore - it came out in 2015! That's all the more reason that it's time for us to understand what it brings. Because if you eventually want to use a frontend framework like ReactJS, you need to know this stuff!

Project Setup

Before we dive in and meet Godzilla, you should totally code along with me. To do that, use the download button on this page to get the course code. When you unzip it, there will be a start/ directory which will have the same code that I have here. Check out the README.md file for witty banter and setup instructions.

The last step will be to open a terminal, go into the directory and run:

php bin/console server:run

to start the built-in PHP web server. Find your browser and open http://localhost:8000. You can login with ron_furgandy, password pumpup. Welcome back to LiftStuff. Our app for keeping track of everything we lift during the day to stay in top shape. This is a Symfony application, but that's not really important: almost everything we've been doing lives inside a single JavaScript file called RepLogApp.js.

New Shiny JavaScript Version?

Now, about this new JavaScript version. From time to time, every language comes out with new versions. In our world, the PHP core team dreams up some new ideas, writes a bunch of code, and then releases it. We all happily install the new version on our servers and use the cool new stuff!

JavaScript is no different. Wait, that's not right! JavaScript is totally different. When a new version of JavaScript comes out, well, what does that even mean? Because there isn't just one JavaScript, there are many: Chrome has a JavaScript engine, Internet Explorer maintains its own... crappy one, and of course, Node.js is another JavaScript engine. So when the JavaScript community decides it wants to add a new function... well, it can't! All it can really do is recommend that the new function be added... and then wait for all the browsers to add it!

There is only ECMAScript

Ok, the situation isn't that bad. But, JavaScript is not a language like PHP that has one core code. In reality, JavaScript is nothing more than a standard. When a new version of JavaScript is released, it simply means that the core group has said:

Here are some functions and language changes that we think would make JavaScript more hipster. Now, quick, everyone go and implement these!

And guess what? The language isn't even called JavaScript! It's called ECMAScript. And there is a group of smart people that work on new versions of ECMAScript. But unlike PHP, that doesn't mean they're writing code: they're simply deciding what should be included in the next version. Then, it's up to each browser and JavaScript engine to implement that. But as we will learn later... some smart people in the JS world have found a way around needing to wait for browser support...

ECMAScript 2015?

Back to the story: in 2015 - after over 5 years of work - ECMAScript released a new version. What's it called? Um, yea, it has a bunch of names: ES6, ECMAScript 6, ECMAScript 2015, Harmony, or, to its closest friends, Larry. Ok, maybe nobody calls it Larry.

The official name is ECMAScript 2015, though you'll even hear me call it ES6 because it's the sixth version of ECMAScript.

As we'll learn, ES2015 comes with a lot of new functions and tools. But, more importantly, it comes with new language constructs - new syntaxes that weren't allowed before. In fact, it comes with so many new syntaxes, that if you look at a JavaScript file that uses everything, you might not even recognize it as JavaScript.

And that's not okay: because you and I, we need to be able to understand and write modern JavaScript.

Tip

There is already another new version of ECMAScript: ECMAScript 2016. But it only contains a few, minor features.

So here's our mission: jump into the important stuff of ES2015 that will let us understand, and write truly, modern JavaScript. Let's start with my absolute favorite, game-changing feature of ES2015: arrow functions.

Leave a comment!

5
Login or Register to join the conversation

The Symfony version of the exercise is old :(

1 Reply

Hey tilotiti!

You're right! This tutorial is built on Symfony 3.2. But, Symfony is not really the "star" of this tutorial - just something for us to work inside of while we go through all the ES6 stuff. So, I hope you won't let that stop you! Really, there's not much different between this version of Symfony and the latest anyways, other than directory structure.

But if you have any questions or doubts, you can always ask!

Cheers!

Reply

No problem ! This tutorial is pretty dope anyway ;)

Reply
Ernest H. Avatar
Ernest H. Avatar Ernest H. | posted 5 years ago

"Microsoft maintains its own crappy one"... love it!

Reply
GDIBass Avatar

Hahahaha hilarious

Reply
Cat in space

"Houston: no signs of life"
Start the conversation!

This tutorial uses Symfony 3. But, since this is a JavaScript tutorial, all the concepts work fine in newer versions of Symfony.

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": "^7.2.0",
        "symfony/symfony": "3.2.*", // v3.2.14
        "twig/twig": "2.10.*", // v2.10.0
        "doctrine/orm": "^2.5", // v2.7.1
        "doctrine/doctrine-bundle": "^1.6", // 1.10.3
        "doctrine/doctrine-cache-bundle": "^1.2", // 1.3.2
        "symfony/swiftmailer-bundle": "^2.3", // v2.4.2
        "symfony/monolog-bundle": "^2.8", // v2.12.1
        "symfony/polyfill-apcu": "^1.0", // v1.3.0
        "sensio/distribution-bundle": "^5.0", // v5.0.22
        "sensio/framework-extra-bundle": "^3.0.2", // v3.0.19
        "incenteev/composer-parameter-handler": "^2.0", // v2.1.2
        "friendsofsymfony/user-bundle": "~2.0@dev", // dev-master
        "doctrine/doctrine-fixtures-bundle": "~2.3", // v2.4.1
        "doctrine/doctrine-migrations-bundle": "^1.2", // v1.2.1
        "composer/package-versions-deprecated": "^1.11", // 1.11.99
        "friendsofsymfony/jsrouting-bundle": "^1.6" // 1.6.0
    },
    "require-dev": {
        "sensio/generator-bundle": "^3.0", // v3.1.2
        "symfony/phpunit-bridge": "^3.0" // v3.2.2
    }
}
userVoice