Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLeonardo Sandbichler
4,385 PointsWhy should I use this ?
Hey :)
I really don't understand why i should use that ? What advantages does I have ?
Thanks
4 Answers
Angelica Hart Lindh
19,465 PointsHey there,
Arrow functions allow for more concise code and provides some 'syntactic sugar' to ES2015 JavaScript code. In being more concise, shorter and easier to read (in my opinion) they can help reduce the size of your codebase, even if it is a few bytes, every little helps.
In addition, the best and most useful aspect to arrow function are the fact they do not bind their own this object to the function. Before arrow functions each function declaration would bind its own this object to the scope of the function, whereas arrow functions retain the this object of the enclosing context.
I would really recommend reading the explanations in the MDN on Arrow Functions, they explain things clearly with some good examples.
Example: jsFiddle
Adam Lopez
3,475 PointsDoesn't help that code editors such as sublime or dreamweaver don't support const and let syntax as standard though. Just adds another layer of annoyance for any devs relatively new to the game.
Angelica Hart Lindh
19,465 PointsYeh that isn't doing any favors. I'm using Atom editor along with the language-babel plugin https://atom.io/packages/language-babel.
If you are using Sublime maybe this may help with correct ES2015 syntax: https://github.com/babel/babel-sublime
Jeremy Castanza
12,081 PointsDefinitely appreciate this info. I recently moved to using VS Code as my go-to editor. Haven't been happier. They support const and let.
Mohamed Hak
17,195 PointsHey Adam Lopez, Dreamweaver support ES6 if you change some settings 1- go to preferences if you are on Macβand select "Linting" 2- Make sure Enable Linting is checked and select JS from the options and click Edit & Apply changes 3- a JS.jshintrc file will open and you can change some settings as you like for ESLint 4- add this to the code "esversion" : 6, 5- save the file then close it and close all other files you working on and reopen them again Now, β ES6 works just fine and now you know where to change settings for other JS Linting, for example I changed strict to false because it keeps asking me to use strict in my code.
Good Luck
Thomas Dimnet
Python Development Techdegree Graduate 43,629 PointsHi there!
In addition to the previous posts, you can also use Visual Studio Code. This lightweight editor has a great support ofr ES2015 (and Typescript and Angular JS). I highly recommend you to give it a try ;).
Thomas.
Andres Ramirez
18,094 PointsI've always used Sublime Text for coding... Looks like I will be looking for a new text editor. Does Brackets support ES2015?
Alexander Kapriniotis
25,897 Pointsi would recommend checking out PHPStorm from JetBrains. We use it in the office and personally i love it the project management is really good