Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Here's a little bit for you. Most people prefer the semantics of `let` to `var` for variable declarations in JavaScript. It's how JavaScript should have been designed from the start. It has been officially standard for a year or two and became available in some browsers even earlier.

I want to use `let` (and `const`) for everything and never use `var` again, but I couldn't even do that on my own PRIVATE website (for me alone) until today, because I didn't upgrade my iPhone to iOS 10 until last night, and iOS Safari never supported `let` (or arrow functions or so many other things) before v10 (and Apple won't allow anyone to break their browser monopoly on their platform).

I could just use Android, but I can't switch everyone else to Android, and LOTS of Android and Windows (and even Mac) users are stuck with even older browsers, because they don't know how to (or can't) upgrade.

Are there any ES6 constructs that would require transpiling, to work fine on, say, Chrome or Firefox?

Not on the latest Chrome or Firefox, but that hardly matters in a world where so many people aren't using the latest Chrome or Firefox. The question for a developer is not whether some in their market can run their software but whether some CAN'T.

Is ES6 not completely backward compatible with ES5?

It is (in practice) completely backward compatible, but I suspect you are a little confused about what that means. It doesn't mean "forward compatible". Backward compatible means that a new ES6 browser is still compatible with old ES5 code, which it is. Old ES5 code will keep working. It does NOT mean that my new ES6 code, full of `let` and arrow functions will run in an old ES5-only browser, and there are still plenty of them out there.

As long as you choose to target a market that includes ES5-only browsers (and you may or may not, but if you do), the things that are new in ES6 (Google "what's new in ES6") have to be transpiled to ES5 to run in ES5-only browsers.



I get "const", but is "let" really that big a deal? Are your functions so deeply nested that you need block scope inside of if statements and for loops? (vs forEach callbacks or IIFE blocks or simply splitting complicated stuff into smaller functions)

There is some cool stuff in ES6, but "let" is kind of a yawn, and "class" most definitely is NOT something I really needed.

But I'm still running ES5 on IE11 at work, so it's academic :-(


Sometimes you just need to do something the old way:

  let element = document.getElementById('some-element');
  while (element) {
    // do something
    element = element.parentElement;
  }
let doesn't get in the way with behavior such as hoisting, and the code will break if you redeclare a variable.


How does var/hoisting get in the way of that, or at least, that particular, construct?

FWIW, that would also be a nice "for" loop :-)

    var el
    for (
        el = document.getElement... ;
        el ;
        el = el.parentElement
    ) {
        // do something
    }




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: