THE JAVASCRIPT FUNCTION

THE FUNCTION

FIRST CLASS FUNCTION In this post we will talk about the fundamental characteristics of Javascript functions. We will talk about very important concepts such as abstraction, encapsulation which was used in ES5 called IIFE, the keyword this etc. Translating this definition with regards to JS functions it means that everything we can do with strings numbers etc. we can do it with functions. Just as we can assign a variable to a number, a string etc. so we can assign that variable to a function. Let's see a code example to clarify these concepts. [...]

By |2024-11-11T18:26:11+00:00April 14, 2022|0 Comments

THE PARAMETERS OF THE FUNCTIONS

ARGUMENTS, REST AND SPREAD Parameters passed to a function are also available through the arguments object, it is an array-like object with which it is possible to access the elements passed as input. The following code clarifies this topic. THE PARAMETERS OF THE FUNCTIONS A JavaScript function does not perform any checks on parameter values (arguments). Earlier in this tutorial, you learned that functions can have parameters: function functionName(parameter1, parameter2, parameter3) {   // code to be executed } The function parameters are the names listed in the function definition. The arguments to the function are the real values [...]

By |2024-11-11T18:26:42+00:00April 15, 2022|0 Comments

INVOCATION OF FUNCTIONS

INVOCATION OF FUNCTIONS Code within a JavaScript function will be executed when "something" invokes it. The code is not executed when the function is defined but when the function is called. It is common to use the term "calling a function" instead of "calling a function." It is also common to say "call up a function," "start a function," or "execute a function." In this tutorial we will use invoke, because a JavaScript function can be invoked without being called. function myFunction(a, b) { return a * b; } myFunction(10, 2); // Will return 20 The function above does [...]

By |2024-11-11T18:27:13+00:00October 30, 2022|0 Comments

THE ARROW FUNCTIONS

ARROW FUNCTION Arrow functions are a new type of anonymous functions, introduced in ES6, they have a compact and easily readable syntax. Arrow functions are particularly suitable as callbacks. Arrow functions allow us to write shorter function syntax: let myFunction = (a, b) => a * b; Before the arrow functions we had: hello = function() {   return "Hello World!"; } With the arrow functions we have: hello = () => {   return "Hello World!"; } It gets shorter! If the function has only one statement and the statement returns a value, you can remove the parentheses and the return keyword: hello = [...]

By |2024-11-11T18:27:44+00:00March 31, 2022|0 Comments

THE JAVASCRIPT CLOUSURES

JAVASCRIPT CLOUSURES JavaScript variables can belong to the local or global scope. They can be made local (private) with closures. GLOBAL VARIABLES A function can access all variables defined within the function, like this: function myFunction() {   let a = 4;   return a * a; } But a function can also access variables defined outside the function, like this: let a = 4; function myFunction() {   return a * a; } In the last example, a is a global variable. In a web page, global variables belong to the window object. Global variables can be used (and modified) by all scripts in the page (and window). In [...]

By |2024-11-11T18:28:15+00:00April 16, 2022|0 Comments
Go to Top