DEV Community

frk-ozbk
frk-ozbk

Posted on • Edited on

What is Syntactic Sugar

Today I wanted to talk about syntactic sugar and how it improves you and your team coding life.

In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express.

Let's look at this example. I have an array of items. And I want to check every item is selected or not?

Classic Javascript Loop

example-1

Javascript array method - .every()

example-1

Which one do you prefer using? I think .every() is cleaner and it explains itself.

Let's look at example two. This time I want to select all items if all items are not selected. If all items are selected, I want to remove all items.

Classic Javascript Loop

example-2

Javascript array method - .forEach()

example-2

It is not shorter too much. But still, it is shorter and it is self-explanatory.

Conclusions

Syntactic sugar improves your coding life. Believe me every line matters.
If you are using React or Vue you will have many methods and JSX or Templates in a single component. That is for this post.

Top comments (0)