80% of everything is crap.
The weird edge cases in JavaScript are easily avoided when teaching a subset of es2016 to new programmers.
The basics: variables, loops, functions, etc... are all fine. It's got pretty good functional programming support, too, for beginners.
It's not a "purity" point of view, it's an "ease of use for the purpose" point of view. JavaScript does weird things that stymie experienced devs - a newbie hitting them will be completely lost. What's worse, as I said, is that it does these things because it's poorly designed/its design doesn't adequately cover all the edge cases it should, so newbies will learn the wrong information about why things do or don't happen.
The edge cases are not easily avoided because you don't know what a beginner will or won't try to do when working on their own. That means that not only might they do an okay thing in most languages that doesn't work in JS, but that they may also do something BAD that DOES work in JS, because JS is weird. For instance, the way JS handles variable hoisting and scoping is bonkers compared to most other languages - not stuff you can avoid while learning to program, and making it easy to learn the wrong practice as a result.
"80% of everything is crap" is a good thing to know when doing development work, but it isn't helpful when learning. The goal of learning in this context is mastery of the basics of development; 80% won't be good enough.
JavaScript has been ruined by professional programmers (mostly Rubyists) who never learned how to use the object model, or how to structure functional code well. So we get ES6 classes and promises and async and all of this junk that makes the language impossible to build and debug.
And I say this as a full time JavaScript programmer of ~5 years, after ~5 years of Ruby. I love both classic JavaScript and Ruby, but ES6 is an abomination.
node -v
v0.12.7 const getTweets = (username) => return fetch(`https://api.twitter.com/${username}`)
getTweets('nevon').then(console.log).catch(console.error)
Really isn't that bad, although you have to know promises. With regular callbacks, I guess you have to know that functions can be passed as arguments, but you'll have to learn that quite soon regardless. const getTweets = (username, callback) => {
const req = new XMLHttpRequest()
req.onload = function () {
return request.status === 200 ? callback(undefined, JSON.parse(this.responseBody)) : callback(Error(request.statusText))
}
req.onerror = callback
req.open('get', `https://api.twitter.com/${username}`, true)
req.send()
}
getTweets('nevon', (err, tweets) => {
if (err) {
console.error(err)
} else {
console.log(tweets)
}
})
Most of the confusing crap in there is because of XMLHttpRequest, not asynchronicity.With async functions, which I personally am not a huge fan of, you can get synchronous looking code if you believe that's more beginner friendly:
async function getTweets (username) => {
const response = await fetch(url)
return response.json()
}
getTweets('nevon').then(console.log).catch(console.error)But of all the languages not to pick, I'd content that JavaScript is one of the very worst. (PHP and anything Visual Basic are honorable mentions.)
> `Object.create`
:(
Understanding prototypal inheritance seems essential to me, and Object.create() is the cleanest way to show it in action.
The book also presents the alternative class syntax and numerous ES2015 additions like block-scoped variables and arrow functions, to name a few.
https://www.amazon.com/Front-End-Web-Development-Ranch-Guide...