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
Classes in JavaScript have undergone a significant transformation since the introduction of the current syntax in 2015. Previously, JavaScript used constructor functions to create objects, an efficient but complex method for some developers, especially those familiar with object-oriented programming languages such as Java. The new class syntax not only simplifies this process, but also provides a "sugar syntax" that is more intuitive and familiar to programmers.
A class in JavaScript acts as a blueprint for creating objects. Think of it as a mold, from which multiple instances or copies of an object can be built. The class definition makes it easier to structure and organize coding, as it allows you to clearly separate the properties and methods that characterize it.
The creation of a class begins with the reserved word class
, followed by the class name, which by convention, begins with a capital letter. After defining the body of the class with braces {}
, the constructor method is introduced. A simple example would be a class Person
with properties name
and age
.
class Person { constructor(name, age) { this.name = name; this.age = age; } greet() { console.log(`Hello, my name is ${this.name} and I'm ${this.age} years old.`); } }}
An instance is a concrete manifestation of the class. Using the word new
together with the class name allows you to create these instances. This process activates the constructor, assigning values to the defined properties.
const persona1 = new Persona('Mariana', 25);persona1.greet(); // Hello, my name is Mariana and I am 25 years old.
Prior to 2015, constructor functions were the primary alternative for emulating class structures. However, these could be less intuitive, especially for those unaccustomed to the detailed use of prototypes and this in their implementation. Modern class syntax is cleaner and more aligned with other languages, reducing barriers for those migrating from older platforms.
JavaScript is constantly reinventing itself, and the ability to adapt to these evolutions allows developers to create more robust and efficient applications. Learning about classes not only opens the door to more structured code, but also strengthens the knowledge base in object-oriented programming. Continue to explore and strengthen your skills in JavaScript and beyond!
Contributions 18
Questions 1
Want to see more contributions, questions and answers from the community?