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

141
Vistas
Arrow function gives undefined

I am currently learning canvas and js that comes with it in HTML. I've bumped into a problem that I cannot understand, but I want to.

I am struggling to understand why arrow function returns undefined, while casual func returns HEX code like normal.

Here's the code:

document.querySelector('#color').oninput = () => {
    myColor = this.value;
    console.log(this.value)
}
canvas.onmousedown = (e) => {
    canvas.onmousemove = (e) => {
        let x = e.offsetX;
        let y = e.offsetY;
        context.fillRect(x - 5, y - 5, 10, 10);
        context.fillStyle = myColor;
        context.fill();
        
    }
    canvas.onmouseup = () => {
        canvas.onmousemove = null;
    }

}

It returns undefined

But, if I change code like this:

document.querySelector('#color').oninput = function () {
    myColor = this.value;
    console.log(this.value)
}

It returns HEX.
What seems to be the issue?

about 4 years ago · Santiago Gelvez
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