Category: 4. Advanced working with functions

  • JavaScript Arrow Functions Revisited

    Arrow functions have both some useful and unique features and limitations that we are going to cover in this chapter. In JavaScript, you can meet a lot of cases when it’s necessary to write a small function, which is executed in another place. To be more precise, let’s consider several examples: arr.forEach(func) – for each array item func is executed by forEach. setTimeout(func)– the…

  • JavaScript Function Binding

    In this chapter, we are going to represent the function binding: a method creating a new function that, when called, has its this keyword set to the provided value. Now, imagine that you pass object methods as callbacks, for example, to setTimeout, and there exists a known issue: losing this. Let’s see how to fix it. Losing “this” You…

  • JavaScript Decorators and Forwarding, Call / Apply

    In JavaScript, you can work with functions with excellent flexibility. You can pass them around, use them as objects. In this chapter, we are going to show you how to decorate them and forward calls between them. Using “func.call” for the Context You can use a unique built-in function method func.call(context, …args), allowing to invoke a…

  • JavaScript setTimeout and setInterval

    JavaScript allows you not only to invoke the function right now but also a particular time later. The latter is known as a “scheduling call.” Two main methods can be highlighted for it: These methods are generally supported in all browsers, as well as Node.js. setTimeout For setTimeout this syntax is used: It has the following parameters:…

  • JavaScript The “new function” Syntax

    There is another way of creating a function. It’s not used often, but in times, there is no alternative. Here is the syntax that can be used for function-creating: It is created with the following arguments: arg1…argN and the functionBody. It is demonstrated in the following example: In another example, you can see a function without arguments but…

  • JavaScript Function object, NFE

    In the previous chapters, we have already learned that functions in JavaScript are values. Also, each JavaScript value has a type. Now, it’s time to learn the types of functions. Functions are objects in JavaScript. It is possible not only to call objects, but to deal with them as objects (add or remove properties, pass…

  • JavaScript ‌‌Global‌ ‌Object‌ ‌

    An‌ ‌object‌ ‌that‌ ‌constantly‌ ‌exists‌ ‌in‌ ‌the‌ ‌global‌ ‌scope‌ ‌is‌ ‌called‌ ‌a‌ ‌global‌ ‌object.‌ ‌ In‌ ‌‌JavaScript,‌‌ ‌the‌ ‌global‌ ‌object‌ ‌supplies‌ ‌‌variables‌‌ ‌and‌‌ ‌functions‌‌ ‌that‌ ‌can‌ ‌be‌ ‌ available‌ ‌everywhere.‌ It‌ ‌is‌ ‌called‌ ‌a‌ ‌‌ ‌‌window‌‌ ‌in‌ ‌the‌ ‌browser,‌ ‌‌ ‌‌global‌‌ ‌-‌ ‌in‌ ‌Node.js,‌ ‌and‌ ‌can‌ ‌have‌ ‌other‌ ‌ names‌ ‌in‌ ‌different‌ ‌environments.‌ Lately,‌ ‌a‌ ‌standardized‌ ‌name‌ ‌‌ ‌‌globalThis‌‌ ‌was‌ ‌added‌ ‌for‌ ‌the‌…

  • JavaScript The Old “var”

    In this chapter, we represent the old scripts. It’s not about writing new codes. Let’s start at the very beginning. As you have already learned, there are three main ways for variable declaration: The var originates from ancient times and is different from the other 2. In general, it is not used in modern scripts. var may seem similar to let,…

  • JavaScript Variable scope

    JavaScript is one of the most function-oriented programming languages. In JavaScript, it is possible to create a function, dynamically passed as an argument to another function, and called from a different place of code after. Variable scope is one of the first things to learn in JavaScript.The location of the variable declaration controls the scope of…

  • JavaScript Rest Parameters and Spread Syntax

    JavaScript has a range of helpful features allowing developers to work with arrays and function parameters much effortlessly. In this chapter, the rest parameters and spread syntax are covered. Rest Parameters … The rest parameter gives you a robust way to work with an indefinite quantity of parameters. For better understanding what rest parameter is,…