Coding since 11yo, that makes it over 30 years now ~~~
Have a PhD in Comp Sci ~~~
Love to go on bike tours ~~~
I try to stay as generalist as I can in this crazy wide place coding is at now.
Love it. That's really counterintuitive but makes sense.
As a carry over from working in c and c++ I've always enclosed any case blocks that define variables in curlies, since it avoids redeclaring variables if you have two cases declaring under one name (a similar issue to this one).
So, my code would be:
functionhandleError(error){switch(error){case404:console.log("Document not found");break;case500:console.log("Server Error");break;default:{consterror={msg:"Got an unknown error code",timestamp:Date.now()};console.log("Unknown Error Incident",error);}break;}}handleError(404);// should log "Document not found", now it does
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Love it. That's really counterintuitive but makes sense.
As a carry over from working in c and c++ I've always enclosed any case blocks that define variables in curlies, since it avoids redeclaring variables if you have two cases declaring under one name (a similar issue to this one).
So, my code would be: