JavaScript 6 for the C# Developer: Mini Series – Part 1: How do I iterate?


C# developers, you may not realise how similar many of the language’s features are to those in the next version of JavaScript. The next version of JavaScript, version 6,  has many syntactic feature changes that have been inspired by their equivalents in C#.

Lately I’ve been covering a lot of the cultural aspects of a developers’ working environment, but I thought it was a good time to talk technical. This will be the first in a series of posts on this topic, which I’ve been looking forward to writing for some time now. My aim is to help you as a fellow C# developer gain insight into the ease and awesomeness of JavaScript.

JavaScript is becoming very powerful, it’s amazing some of the things I have seen done. For example, the very popular NodeJs platform for backend HTTP services. There is a Linux VM that you can run, built entirely in JavaScript. Also, check out the Mozilla Shumway project. Browsers are now factoring out support of Flash in their latest releases, but still, there are many many websites out there that require Flash support. Shumway is essentially an ActionScript to JavaScript transpiler which will allow browsers to stop supporting Flash, but still support the website that runs against Flash, it’s truly awesome!

There is never a better time than now to join the JavaScript bandwagon. What’s even more exciting is that the ECMAScript committee are embracing a much more frequent release cycle now. JavaScript 5 came out just over 5 years ago; version 6 is scheduled for release mid-way through this year. But, they are already working on version 7, with rumours that we could see this version out next year! This combined with the wave of Evergreen browsers gracing the scene shapes a truly exciting landscape for the front-end development world. When JavaScript 7 does indeed grace us with its presence, we won’t have to worry about upgrading our browser, the browser will do that for us to support version 7. Even IE will support the evergreen movement with Project Spartan. But of course with every upgrade comes some down sides, how do we support older browsers that can’t upgrade auto-magically? Well, the answer is in a previous point, transpiling. We can use tools like Traceur or Babel (formally 6To5) to take our JavaScript written in 6 and transpile it to version 5 to support browsers with this requirement. There really is never a better time than now to join this JavaScript movement.

Enough intros, time to get back to the purpose of this post. How do I iterate in JavaScript 6 that’s similar to C#? Well I will begin with presenting you with how we know it’s done in C#:

So let’s say we have a list of iterable shapes we need to iterate over; a square, rectangle, circle and a triangle, how do we iterate through these?


Pretty simplistic, nothing special going on here. We simply iterate through the list of shapes and print their name and colour to the console. But how would we do the same in the new JavaScript 6?


With the exception of the access modifiers and return type in the C# equivalent, there isn’t too much difference between the two implementations. They both achieve the same thing with nearly the same number of lines of code. The transition of writing JavaScript is only a slight paradigm shift away. But not much, as we’ll explore in the upcoming articles on JavaScript 6 for the C# developer.

Thanks for reading and keep building awesome.

Until next time!

Ian B
P.S. You can also find me on Twitter: @ianaldo21

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s