I'm simply running a function which checks if the variable year is set if not then set it new Date().getFullYear().
The error I get:
Uncaught ReferenceError: year is not defined
year = (year) ? year : new Date().getFullYear();
console.log(year);
Why can't I check if year exists and if not set it?
year = year || new Date().getFullYear();
Useful to check function parameters
year = year ?? new Date().getFullYear();
another way
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With