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

163
Views
¿Por qué el resultado de la ejecución del código es 10? sintaxis JS

El código es:

 x = 10; if (x > 1) { var x = x + 1; } console.log(x); var x;

La salida de la ejecución del código es: 11

¿Por qué son las 11? , y ¿Por qué no es un error?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Descripción

Las declaraciones de var, dondequiera que ocurran, se procesan antes de que se ejecute cualquier código. Esto se denomina elevación y se analiza más adelante.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/var#description

Esto significa que no importa dónde esté su "var x", cuando se procese este script, la declaración será la primera.

about 4 years ago · Juan Pablo Isaza Report

0

Debe comprender cómo funcionan realmente los cierres .

 // You define 'x' variable [1] in global scope x = 10; if (x > 1) { // You define another one 'x' variable inside of 'if' scope // So here (inside of 'if') you will interact with this variable, // not with first one ([1]) var x = x + 1; } // You code run out of 'if' so you're working with // global scope again, and your 'x' is first one [1] console.log(x); // x = 10 still var x;
about 4 years ago · Juan Pablo Isaza Report
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!