DEV Community

Discussion on: What to know about JavaScript

Collapse
 
jochemstoel profile image
Jochem Stoel

When writing for both beginners and professionals, I recommend talking about the different dialects in JavaScript, why they exist and when to use them. Many people with reasonable JavaScript experience on first glance have no idea what each other's code means, find it to be very unusual or start arguing against it.

I will write a post about it and get back to you here.

Collapse
 
kayis profile image
K

Now I'm intrigued, haha :D

Collapse
 
jochemstoel profile image
Jochem Stoel

Hey K. I am kind of busy lately so I haven't had the time or energy to write a post about it but I feel it is polite to at least say something.

By dialects I mean the different notations/styles used by different people over time.

We used to have a readystate (for instance with XMLHttpRequests) and an onreadystatechange. We hang a function on the statechange event and see what the readystate is. Some developers don't use a statechange anymorebut implement onChange, onCreate, onError etc.
Since a year or two (three?) it has become common to implement the on() method.

Object.addEventListener('change', function(event) {
    // 
})

became

Object.on('change', event => {
    //
})

And of course there's Promises and now async/await. All of them ultimately doing the same thing but with different notation.

To a developer with a background in C++ or C# things the old notation comes very natural. (addEventListener) when people like this see the fetch API in modern browsers at first glance they are like "say what??". This is what I meant with developers getting confused by each other's code even though they both know the language quite well.

Another dialect example I can think of is what jQuery does with the function behavior depending on the amount of arguments given. (a single attr method for both element.getAttribute and element.setAttribute)

$('#element').attr('class', 'pretty') // set class = pretty
$('#element').attr('class') // return class value
$('#element').attr() // return all attributes (cheerio)

I hope this explains what I was getting at and gives you some useful info on things to talk about in one of your future articles. If you are writing one or have written one, by all means hit me up for any type of input/feedback. :)

Thread Thread
 
kayis profile image
K

I think I understand what you mean.

I came from PHP to JavaScript and besides some minor things, the whole syntax/gramma seemed reasonable to me.

But the semantics were completely different. The event-loop, the prototype chain etc. were things that didn't have equivalents in PHP.

Thanks for taking the time :)