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

221
Vistas
Uncaught SyntaxError: Invalid left-hand side in assignment: I am not sure what is causing this error?

I have a class Employee that I have imported into a new js file (Main.js) that has an array of objects of a list of employees, but I get an error of Uncaught SyntaxError: Invalid left-hand side in assignment I have attached where I get the error in the console log.

As you can see in the HTML file I have the type = module for both scripts

HTML file

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="module" src="classes.js" defer></script>
    <script type="module" src="main.js" defer></script>
    <title>Javascript Practice</title>
</head>

Classes.js file

export class Employee{
    constructor(
        id,
        name,
        surname,
        jobtitle,
        salary,
        startDate
        ){
       this.id = id;
       this.name = name;
       this.surname = surname;
       this.jobtitle = jobtitle;
       this.salary = salary;
       this.startDate = startDate;
    }
    id = Math.floor(Math.random() * 1000) + (new Date()).getTime();
}

Main.js file

import { Employee } from "../classes.js"

const employees =[
    new Employee = {
        id:id,
        name:"Paul",
        surname:"Jakens",
        jobtitle:"Senior Salesmen",
        salary: 13000,
        startDate:"2015/05/15"
    },
    new Employee = {
        id:id,
        name:"Susan",
        surname:"Lupan",
        jobtitle:"Junior Designer",
        salary: 12000,
        startDate:"2021/03/16"
    },
    new Employee = {
        id:id,
        name:"John",
        surname:"Angel",
        jobtitle:"Senior Full Stack Developer",
        salary: 40000,
        startDate:"2014/10/18"
    },
]

Image of error

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

0

Because the employee is a class instead of an object, I think you have to call the constructor.

So this should be what the employees would look like

const employees = [
  new Employee(id,"Paul","Jakens","Senior Salesmen", 13000,"2015/05/15")
  ...
]

Also you can remove the id from the constructor since you're randomizing it

constructor(
        name,
        surname,
        jobtitle,
        salary,
        startDate
        ){
       this.id = Math.floor(Math.random() * 1000) + (new Date()).getTime();;
       this.name = name;
       this.surname = surname;
       this.jobtitle = jobtitle;
       this.salary = salary;
       this.startDate = startDate;
    }
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