Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
Syntax Error of function variable in Javascript

I am using node version 12.22.6.

I don't understand, how this code is wrong.
I'm probably missing some important basic thing, but just cannot figure it out.

const change_vars = (var) => {
    console.log(var + " is a " + typeof(var) + "\n");
}

const variables = [
    42,
    "42",
    {number: 42},
    {},
    true,
    undefined
]

variables.forEach(var => change_vars(var));

node vars.js

$ SyntaxError: Unexpected token 'var'

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

var is a reserved keyword in javascript. Use another variable name.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can't use a reserved word to name your variables, you can find the full list here:

  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar

But some examples include:

break
case
catch
class
const
continue
debugger
default
delete
do
else
export
extends
finally
for
function
if
import
in
instanceof
new
return
super
switch
this
throw
try
typeof
var
void
while
with
yield

Long story short makes sure your variables are not named the same as the reserved words.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can't name your variable var as that is a reserved word in javascript.

(Unrelated: I recommend using camel-case for variables; changeVars instead of change_vars)

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda