⤳ The error “TypeError: getElementById is not a function” happens for two common reasons (Based on StackOverflow users): Here’s what this error looks like in the browser’s console: How to fix the “TypeError: getElementById is not a function” error Before anything, let’s have a refresher from ...
⤳ If you’re getting the “AttributeError: ‘str’ object has no attribute ‘decode’ error, you’re probably calling decode() on a string object (str) in Python 3. Here’s what the error message looks like in the Python shell: Python 3 stores a string as a sequence of Unicode ...
⤳ The error “Cannot use import statement outside a module” occurs when you use the import statement outside an ES (ECMAScript) module. If you’re using Node.js, you need to set Node’s module system to ES modules – by adding type: "module" to your package.json (note the ...
⤳ If you’re looking for Javascript shorthand for if/else statements, you’re probably looking for the ternary – a.k.a the conditional – operator. JavaScript ternary operator takes three operands: a condition followed by a question mark (?), and two JavaScript expressions separated by a colon (:). The expression on ...
⤳ What are those double not operators in JavaScript? You might have noticed the JS double exclamation mark (!!) in a code snippet, and you may be curious what that means. First, “double exclamation mark” (a.k.a the “double bang”) isn’t an operator itself. It’s two logical not ...
⤳ If you need to get the day of the week in JavaScript, you can do so with the standard Date object methods – without using a third-party library. The Date object can give us the day of the week in the following formats: Using Date.prototype.getDay() ...
⤳ To subtract a few days from a date in JavaScript, you need to use setDate() on a Date object and decrement the current day of the month – returned by getDate() – by one or more days. You can do it in three steps: For instance, to get the ...
⤳ To add a few days to a date in JavaScript, you need to use setDate() on the Date object and increment the current day of the month by one or more days. You can do it in three steps: For instance, to add 5 days to a ...
⤳ To get yesterday’s date in JavaScript, you need to get today’s date and use setDate() of the Date object to subtract a day from it. It’s quite easy to implement; You can do it in four steps: Let’s write the code: In the above example, ...
⤳ The error “__dirname is not defined in ES module scope” occurs if you refer to the __dirname global variable in an ES (ECMAScript) module. Here’s what the error message looks like: This global variable contains the path to the current module’s directory. The __dirname and ...