Introducción a JavaScript
¿Por qué aprender JavaScript?
¡Hola Mundo! en Mac
¡Hola Mundo! en Windows
Anatomía de una variable
Tipos de datos en JavaScript
Creación de strings
Operadores aritméticos
Conversión de tipos: Type Casting y Coerción
Conversión de tipos explícita e implícita
Estructuras de Control y Lógica
Operadores de comparación
Operadores lógicos
Ejecución condicional: if
Ejercicio: Adivina el número
Ejecución condicional: switch
Loop: for
Loop: for of
Loop: for in
Loop: while
Loop: do while
Funciones y This
Anatomía de una función
Funciones vs Métodos
Funciones puras e impuras
Arrow function y enlace léxico
Contextos de ejecución y scope chain
¿Qué es Closure?
Preguntas a Desarrolladores Senior: ¿Por qué aprender Desarrollo Web?
Manipulación de Arrays
Introducción a Arrays
Mutabilidad e inmutabilidad de Arrays
Modificación básica del final con push( ), pop( )
Iteración con map( ) y forEach( )
Filtrado y reducción con filter( ) y reduce( )
Búsqueda de elementos con find( ) y findIndex( )
Crear copias con slice( )
Spread operator: casos de uso
Programación Orientada a Objetos
Anatomía de un Objeto
Trabajando con objetos en JavaScript
Función constructora
¿Qué es una clase?
Prototipos y herencias
Herencia en la práctica
Prototipos en la práctica
this en JavaScript
Proyecto: Crea una red social
Proyecto: Crea una red social parte 2
Asincronía en JavaScript
¿Cómo funciona el JavaScript Engine?
Promesas en JavaScript
Usando Async y await en JavaScript
For await of
¿Cómo funciona la web?
¿Cómo funciona HTTP?
Método GET en JavaScript
Método POST en JavaScript
Método DELETE en JavaScript
Importancia del id en el método DELETE
ECMAScript 6 y tus siguientes pasos
You don't have access to this class
Keep learning! Join and start boosting your career
JavaScript, an essentially object-based programming language, offers impressive versatility when it comes to working with both functions and methods. The main difference between a function and a method lies in their uniqueness and use within the code. In this content we will explain the differences and similarities between the two, showing you how to take full advantage of these functionalities in your program.
JavaScript functions are blocks of code designed to perform a specific task. When we write a function, we create and call it, and the JavaScript interpreter identifies them as elements of type "function". But did you know that functions are actually objects? This means that they have properties and methods.
Passing functions as arguments: This is a concept known as "callback". A function can be passed as an argument to another function, allowing you to modularize and execute code once a particular event occurs.
function A() { console.log("Function A");}
function B(callback) { callback();}
B(A); // Call function B, passing A as callback.
Return functions: It is possible for a function to return another function, allowing you to create dynamic, reusable functions.
function A() { function B() { console.log("Function B"); } return B;}
const newFunction = A();newFunction(); // Executes function B
Assign functions to variables: In JavaScript, functions can be assigned to variables, becoming 'anonymous functions' or 'function expressions'.
const A = function() { console.log("Anonymous function");};
A();
Another essential feature of functions is that, just like objects, they can possess properties and methods. For example:
Method call
: allows you to explicitly set the context of this
within the function.
const obj = { name: "Object",};
function greet() { console.log(`Hello, I'm a ${this.name}`);}
greet.call(obj); // Output: Hello, I'm an Object
Nesting functions means defining functions inside other functions. This technique allows you to logically group related functions and manage variables in a structured way.
Nested functions: In JavaScript, it is possible to access variables external to a function from another, more internal function, while maintaining access to its variables, which is one of the key concepts behind closures.
function A() { const message = "I am function A";
function B() { console.log(message); }
B();}
A(); // Will call function B, printing "I am function A".
Yes, it is entirely possible to store functions in objects. When a function is stored as a property of an object, it is known as a method of the object.
Methods on objects: Here is an example of how a function can be defined as a method of an object.
const rocket = { name: "Falcon 9", launchMessage: function() { console.log("Successful launch! 🚀"); } } };
rocket.launchMessage(); // It will execute the method and display "Successful launch! 🚀"
In summary, both functions and methods are essentially powerful tools in JavaScript. With these, you can structure your code more efficiently, create reusable functions, modularize the flow of your program, and effectively manage execution contexts. Continue exploring how functions and methods can improve the quality and functionality of your projects.
Contributions 35
Questions 1
Want to see more contributions, questions and answers from the community?