Some of you made some awesome javascript courses which I follow eagerly in the adventure to become a better developer.
One of these courses was about EcmaScript6 const and let variables and the Try and Catch statement. So as a curious junior developer I tried it myself by declaring an arrow function in a constant and trying to change the constant:
const userValidation = (userValid) => userValid == true ? "You may enter" : "You may not enter, sorry.";
try {
var userValidation = function(userID) {
//Execute some code which ofcourse will never execute
}
}
catch(err) {
console.log("Woops, something went wrong.");
}
console.log(userValidation(false));
The behaviour which I expected was the error message: "Woops, something went wrong." because I already declared the constant "UserValidation". But that was not what was happening, instead the console just gave the error and dies:
What am I doing wrong?