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

139
Views
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
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!