Live Lesson — Diving into ES2015
SitePoint Premium’s first ever Live Lesson was held this month with Darin Haener, walking you through several sections of his Premium course, Diving into ES2015. Viewers were able to ask Darin questions while he went through parts of his own course, and provided the most accurate answers possible.
Hop over to the recorded Live Lesson with Darin Haener, if you haven’t seen it! In this post we’ll highlight the main points that were made and questions that were answered during the Live Lesson.
SitePoint Premium’s Live Lessons
These Live Lessons are new at SitePoint, and they are geared towards helping you to thoroughly understand the content in various parts of SitePoint Premium, and let you interact with other developers via the chat during the lesson, as well. They’re also an excellent preview of what SitePoint Premium’s courses are like, and the kind of information available in them. You can participate in this event and learn a lot, whether you have taken the course already or whether you’ve never even seen it. All are welcome!
Diving into ES2015
Darin explains that with the arrow functions in ES2015, when you use an arrow function it automatically binds that function to lexical
this. That, and the condensed responses that can come out of arrow functions, make for quicker code writing and can make your code much easier to read, and arrow functions are one of the reasons that ES2015 is as popular with developers as it is.
Destructuring is an amazing feature of ES2015, and provides an incredibly easy way by which to assign variables. Darin goes over using destructuring as a handy way to extract elements from objects without having to type out an entire path. Additionally, restructuring also allows for easily setting of default values in arrays and objects without causing problems, and you’ll also get a feel for this in the video.
As far as parameter handling goes, Darin explains that parameters can be manipulated in a variety of new ways in ES2015, such as giving parameters inline default values in the function call, rather than handling that inside of the function itself. It also allows rest parameters to be given, allowing as many arguments as needed to be inserted as array values, and the use of the spread operator within arrays.
Questions from Viewers for Darin
Darin Haener: Most browsers have already adopted ES2015. If your code still runs, then yes (it’s fine). I don’t know off the top of my head anything that was deprecated or removed. As far as I know, there have only been additions.
I think you’re probably safe to continue writing code the way you used to, although I don’t know that I would recommend it, because you get left behind.
Q: What is the difference between const and let?
Darin Haener: First, the difference between
let are both scoped the same, but the difference is
const cannot be redefined. If I, in my code, said
const a = 1, and then later down in the same code block, I tried to say
const a = 3, that would throw an error. It would not allow me to, or even if I just tried to say
a = 4, even without saying
const, it would not allow me to reassign that variable.
let will let you do that. So if you said
let b = 1, then later on in the same code block, you could reassign it and say
b = 3, and that’s allowed.
let, you get the same type of scoping, and just slightly different behavior.
Q: I usually see constant variables defined with capital letters — for example, const MYAGE = 20. Is that a requirement or just a good practice?
Darin Haener: It’s definitely not a requirement, but it probably is a good practice. Most every programming language has constants as capitals, all caps.
Darin Haener: As far as I know, TypeScript is a little more strict. It has a strict typing system. I would say that if you’re more familiar with a language like C that uses strict types, then TypeScript is probably gonna feel more comfortable and familiar to you, so go ahead and use it.
Q: What do you think about coffeescript for ES6?
Learn PHP for free!
Make the leap into server-side programming with a comprehensive cover of PHP & MySQL.
RRP $11.95 Yours absolutely free
Darin Haener: I used to use coffeescript a lot, but I think that ES6 (or 2015) solved a lot of the same problems that coffeescript aimed to solve, and one issue that I had personally (and that’s just my opinion) with coffeescript was the meaningful indentation. I just personally, I’ve never liked that.
Wrapping it Up
If you weren’t able to participate in the Live Lesson, and you have not yet watched the recording, do that now! The Diving into ES2015 SitePoint Premium course is available for your perusal, and Darin’s Live Lesson is an invaluable addition to that if you are going through it, or plan to in the future!
Jeff works for a startup as a technical writer, does contract writing and web development, and loves tinkering with new projects and ideas. In addition to being glued to a computer for a good part of his day, Jeff is also a husband, father, tech nerd, book nerd, and gamer.
Visual Studio Code: End-to-End Editing and Debugging Tools for Web Developers
Your First Year in Code
Jump Start Git, 2nd Edition