Is it necessary to use ES6 syntax? I read that it makes code more readable and clean ,i still find it confusing tho | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Is it necessary to use ES6 syntax? I read that it makes code more readable and clean ,i still find it confusing tho

Also do I have to use forEach Loop ?or can I use for(i of array) Loop or for(i=0;i<array.length;i++)

5th Jun 2020, 8:50 AM
Abhay
Abhay - avatar
13 Answers
+ 10
Abhay I'm assuming your usage of "ES6 syntax" refers to what you might consider to be new features / methods / statements / expressions introduced to the ECMAScript specifications every year since in 2015. Some of these may provide alternative ways of doing the same things from the previous ES5 specs released back in 2009. Whether or not you decide to make use of any language feature, new or old, I strongly recommend you become familiar with them all and understand which tools are best for the various different needs. Otherwise, it's like asking if it's necessary to use any feature introduced in the past decade that you're unfamiliar with for any language. It sounds like the better question would be focused on helping you overcome any confusion with ES6 features. Here is an excellent reference to review ES5 and ES6 equivalents by feature: http://es6-features.org/ Aside from personal preference and aesthetics, there are no cases I can think of where Array.forEach is better than the standard for loop.
7th Jun 2020, 10:21 PM
David Carroll
David Carroll - avatar
+ 6
Well forEach only give the elements of the array For(let I in array) work same as for (let I =0;I<array.length;I++) Also you can use map (element, index) functions also its give index and element E56 is use to make code and standard (already told by Mirielle not going to say anything about it )
6th Jun 2020, 12:34 AM
Coder
Coder - avatar
+ 4
for...of loop is also an es 6 feature 🙄
8th Jun 2020, 7:17 AM
Ore
Ore - avatar
+ 3
Ore Adeleye Sorry for the confusion. Es6 also comprises new OOP syntax such as classes. In fact, js is multi paradigm. Es6 Arrow functions and methods such as map, reduce and filter are geared towards functional programming.
7th Jun 2020, 4:28 PM
Logomonic Learning
Logomonic Learning - avatar
+ 2
No, code with what you feel comfortable with. Eventually you'll find other design patterns and making your code more readable once you start digging deep into other people's code
5th Jun 2020, 9:22 AM
HNNX 🐿
HNNX 🐿 - avatar
+ 2
es6 is geared towards functional programming (fp) in contrast to procedural and object oriented programming. although you can do the same things in each paradigm, fp in general is considered to be easier to test and maintain than oop and procedural programming.
7th Jun 2020, 7:59 AM
Logomonic Learning
Logomonic Learning - avatar
7th Jun 2020, 8:01 AM
Abhay
Abhay - avatar
+ 2
David Carroll thanks a lot ,
8th Jun 2020, 9:28 PM
Abhay
Abhay - avatar
+ 1
But my question is it necessary? As I find it confusing and I am not at all comfortable with it
5th Jun 2020, 9:01 AM
Abhay
Abhay - avatar
+ 1
5th Jun 2020, 9:27 AM
Abhay
Abhay - avatar
5th Jun 2020, 9:39 AM
Ore
Ore - avatar
+ 1
It is not necessary to add ES6 syntax you can just use javascript. ES6 make our code short.
5th Jun 2020, 9:54 AM
Omkar Kamat
Omkar Kamat - avatar
0
Logomonic Learning That is not true. JavaScript is not geared towards any specific paradigm. Classes and generators where introduced in ES 6 which makes OOP possible and easier. So what do you mean?
7th Jun 2020, 4:20 PM
Ore
Ore - avatar