⤳ When working with strings in JavaScript, it’s important to check if a variable is a string before performing any string-related operations – specially when you get the value from an API . This quick guide explores four methods for checking if a variable is a ...
⤳ The JavaScript error “Await is only valid in Async functions” occurs when you use an await expression outside an async execution context, like an async function or top-level body of an ES module (top-level await). How to fix it? First of all, we need to determine where ...
⤳ If you need a cross-browser approach to convert a dd/mm/yyyy string to a Date object in JavaScript, here’s what you need to do: A date string in dd/mm/yyyy format is considered a non-standard date format in JavaScript. That said, it isn’t a good idea to ...
⤳ 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 ...
⤳ 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 ...