callback-hell icon indicating copy to clipboard operation
callback-hell copied to clipboard

Illegal return statement

Open ViavaCos opened this issue 4 years ago • 2 comments

I think you should not write code as below:

if (err) return statusMessage.value = err

There will throw some error like: Uncaught SyntaxError: Illegal return statement

File Path: callback-hell/index.html

ViavaCos avatar Sep 03 '21 06:09 ViavaCos

Then, how should be written this code?

seyerman avatar Feb 09 '22 12:02 seyerman

We cannot return a assignment, if you do and you will get an error as above. So, you just need change returns as below.

if (err) {
  statusMessage.value = err
  return statusMessage.value
}

ViavaCos avatar Feb 23 '22 08:02 ViavaCos