JavaScript

Await is only valid in Async functions error in JavaScript

Await is only valid in Async functions. This syntax error 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). Here’s what it looks like: How to solve “await is only valid …

6 min read

Convert a dd/mm/yyyy string to a Date object in JavaScript

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: Split the date/time components into separate values (year, month, day, hour, minutes, etc.)  Create a Date object with these arguments (details below). …

4 min read

Javascript if/else shorthand explained (with common uses cases)

How to write the shorthand of if/else statements in JavaScript? If you’re looking for the shorthand of if/else in JavaScript, you need to use the ternary – a.k.a the conditional – operator. The ternary operator takes three operands: a condition followed by a question mark (?), and …

3 min read

JavaScript double exclamation mark explained (with examples)

What are those double not operators in JavaScript? You might have noticed a double exclamation mark (!!) in JavaScript code 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 (!) operators …

4 min read