Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
Console.log() registra la salida antes de pasar un argumento en un método de una clase

El siguiente código es un método PUSH de lista enlazada individualmente en javascript que agrega un elemento al valor final en la lista.

¿Cómo es que la primera salida muestra la lista enlazada antes de pasar el argumento dentro del método PUSH()?

El primer archivo console.log registra un objeto vacío de la lista, pero dentro del objeto se dan los valores de los argumentos pasados que se pasan más tarde.

¿Cómo es posible esto?

 class Node { constructor(val) { this.val = val; this.next = null; } } class SinglyLinkedList { constructor() { this.head = null; this.tail = null; this.length = 0; } // PUSH push(val) { const newNode = new Node(val); if (!this.head) { this.head = newNode; this.tail = newNode; } else { this.tail.next = newNode; this.tail = newNode; } this.length += 1; return this; } } // 1st output console.log(list); list.push("Hi"); list.push("You"); list.push(25); list.push(2); // 2nd output console.log(list);

PRODUCCIÓN

1ST consola.log(lista)

 SinglyLinkedList {head: null, tail: null, length: 0} head: Node {val: 'Hi', next: Node} length: 4 tail: Node {val: 2, next: null} [[Prototype]]: Object

2ND consola.log(lista)

 SinglyLinkedList {head: Node, tail: Node, length: 4} head: Node {val: 'Hi', next: Node} length: 4 tail: Node {val: 2, next: null} [[Prototype]]: Object
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!