50 tips of JavaScript

1. Strict equality (Basics)

I’m writing JavaScript for a long time, and one of the first things that I learned is to use === (triple equals) instead of == (double equals).

2. Comma operator (Basics)

I think the comma operator in JavaScript is underestimated. The popular perception is that we use the comma to separate function arguments or items in an array. However, there is another use case.

3. Spread operator (Basics)

Back in the days when I started reading about the new features of JavaScript, I was the most excited about the spread operator. It allows us to expand iterable (or strings) in various places.

4. Destructuring (Basics)

I first saw destructuring in some other language. It took me some time to understand it, but once I got the idea, I couldn't stop thinking how nice will be to have it in JavaScript.

5. Optional chaining (Basics)

My "favorite" error while I'm doing something with JavaScript is "Cannot read properties of undefined". Optional chaining could address those cases.

6. By reference or by value (Basics)

In programming, there is the phrase "passing a variable". That is the moment when we call a function with a given parameter. In some languages ...

7. Reducing (Basics)

Very often, we have to transform objects from one shape to another. My favorite tool for such transformations is the `reduce` function

8. Async/await (Basics)

The topic of asynchrony in JavaScript is huge. That is because the language offers many mechanisms for handling asynchronous operations. Over the years, those mechanisms change.

9. Iterable protocol (Basics)

The iterable protocol is underrated. I don't see people using it, which makes me sad because it's a wonderful instrument.

10. Generators (Basics)

Like the iterable protocol, using generators in JavaScript is not very popular. The community is not betting a lot on this API. I think thought ...

11. Printing JSON (Browser APIs)

Very often, we need to look inside objects. One of my favorite ways to print an object is to use `JSON.stringify` API.

12. Object.assign (Browser APIs)

There are some APIs that I use frequently. `Object.assign` is one of them. For me, the use case is almost always constructing a new object by merging various properties.

13. Capture groups (Browser APIs)

Like most programming languages JavaScript supports regular expressions. I'm writing software for more than 15 years, and I've never been good with this...

14. Tagged template literal (Browser APIs)

Some time ago, we couldn't write multiline strings in JavaScript. We had to concatenate one-liners. Then the template literal was introduced. Suddenly our life became easier.

15. Media query list (Browser APIs)

I saw the first article about responsive design in 2010 (by Ethan Marcotte). Since then, the Web has evolved, and so ...

16. Event delegation (Browser APIs)

I find it very interesting how we start forgetting stuff when technology evolves. One of these things is the event delegation.

17. Error handling (Browser APIs)

There is one thing that developers forget very often - error handling.

18. Blast from the past (Browser APIs)

I remember when copying to a clipboard was done via embedding a small Flash app. Nowadays, we have an API for this.

19. Asynchronous Immediately Invoked Function Expression (Implementations)

Early in this book, we mentioned the async/await syntax. I remember the time when this API came to the language. Our code became ...

20. Asynchronous queue (Implementations)

Sometimes I like to solve problems that libraries already solve. One of those problems is handling multiple async operations one after the other.

21. JavaScript module system as a singleton (Implementations)

There are different types of scope in JavaScript. One of them is the module scope. A variable at the top of the file falls into that scope.

22. Call-to-action widgets script tag replacement (Implementations)

Did you ever wonder how the call-to-action widgets work? You know, those little buttons for sharing content on social networks.

23. Removing fields from objects (Implementations)

Earlier in this book, we learned about the destructuring assignment. An interesting use case of this feature is that it allows us to remove a field from an object.

24. A must have function argument (Implementations)

As we know, JavaScript is not a strictly typed language. We don't have types by default. That is why a big part of the community started using alternatives like ...

25. Loading JavaScript file dynamically (Implementations)

It's funny how in the past we had to write a lot of things alone. There was no NPM or GitHub. We had to write our own loader.

26. Readability (Popular concepts)

There are tons of different opinions on what is a good code. For me, the best answer is, "Good code is the one that I and my teammates understand".

27. The return statement is not the end (Popular concepts)

Even though I'm writing JavaScript for many years, I'm still learning. And I'm getting surprised by simple things. It could be a pattern or just a style of writing.

28. Always get a value (Popular concepts)

JavaScript by default has no type definitions. It has been like that since day one. Today we can solve that by using languages like TypeScript.

29. This (Popular concepts)

There is always one chapter for the `this` keyword in every JavaScript book or course.

30. Scope (Popular concepts)

At the job interviews for JavaScript developers, two questions are almost always asked - the first one is about the `this` keyword (covered in the previous chapter), and the other one is about scope.

31. Manually creating block scope (Popular concepts)

We saw the four different types of scope. I want to share a small tip regarding the block scope. And precisely when we need to create it on purpose.

32. Call, apply and bind (Popular concepts)

When we know what scope is, it's time to explore the `call`, `apply`, and `bind` methods.

33. Chaining (Popular concepts)

Back in the days when the Web was all made of jQuery, we were constantly using a pattern - function (or method) chaining.

34. Recursion (Popular concepts)

Recursion is probably one of the oldest concepts in programming. It's the paradigm where a function calls itself.

35. Higher order functions (Popular concepts)

The main building block of every application is the function. You've probably heard that the functions in JavaScript are first-class citizens.

36. Memoization (Popular concepts)

The previous chapter showed us that the main instrument in JavaScript is the function. And if something is getting run, again and again, it makes sense to try optimizing it.

37. Partial application (Popular concepts)

Developers that used to write in functional languages feel good with JavaScript because the language supports functional concepts. One of them is partial application.

38. Currying (Popular concepts)

Another popular functional programming paradigm is currying. It is kind of similar to the partial application in the sense that it allows us to split the function call.

39. Dependency injection (Popular concepts)

Dependency injection (DI) or inverse of control (IoC) is a concept that is not popular in the JavaScript ecosystem.

40. State machines (Popular concepts)

State machines must be taught equally as every other design pattern in programming. Interestingly, I started seeing state machines everywhere once I found this concept.

41. Reducers (Popular concepts)

Now when we know what a state machine is, we can talk about `reducers`. That term became popular around the Redux library, where it is the main actor.

42. Flux architecture (Popular concepts)

Flux architecture is one of those popular things that the ecosystem replaces with something new. Back in the early days of React, this pattern was the answer to many questions.

43. Redux (Popular concepts)

In this book, the Flux architecture chapter is before Redux on purpose. Historically Redux came after Flux and, it has almost the same structure. The one-way direction data flow is still here.

44. Communicating sequential processes (Popular concepts)

CSP (communicating sequential processes) is a formal language for describing patterns of interaction in concurrent systems. It's used in ...

45. Singleton (Design patterns)

In this section of the book, we will learn about six of my favorite design patterns. The first one is called "singleton".

46. Factory pattern (Design patterns)

Like a singleton, the factory pattern falls into the category of creational patterns. Those are patterns that are focused on the initialization of the objects.

47. Module revealing pattern (Design patterns)

The revealing module pattern is the one that I use the most in my daily job. Back in the days when we didn't have classes, this pattern was my primary tool for mimicking OOP.

48. Publisher/Subscriber pattern (Design patterns)

Often, we use design patterns in programming without even knowing that they exist. The publish/subscribe pattern is one of them.

49. Mixins (Design patterns)

A mixin is a set of helpers that we can inherit. In the world of JavaScript, this is often an object that we merge with another one.

50. Command pattern done with generators (Design patterns)

The idea of the command pattern is to separate the objects that trigger logic from the objects that implement it. The trivial variant involves ...