Web Development

Javascript shorthand for if/else statements explained

⤳ 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 ...

⌛ 3 min read

JavaScript double exclamation mark explained (with examples)

⤳ 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 ...

⌛ 5 min read

How to fix “__dirname is not defined in ES module scope”

⤳ 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 ...

⌛ 2 min read

JavaScript isset Equivalent (3 methods)

⤳ If you’re looking for the JavaScript isset equivalent, you’ve probably used it in PHP before and want the same functionality in JavaScript. As you probably know, PHP’s isset() function checks a variable is declared and not null. Although JavaScript doesn’t have an isset equivalent, there are ...

⌛ 6 min read

Integer division in JavaScript explained

⤳ In this guide, you’ll learn how to do integer division in JavaScript. The division operator in JavaScript (/) divides two numbers (dividend and divisor) and returns the quotient as a floating point number (rather than the quotient and the remainder of a division separately). All numbers in ...

⌛ 4 min read

PHP replace space with dash explained with examples

⤳ If you want to “replace space with dash” in PHP, you can do so with the str_replace() function. We usually replace spaces with dashes to generate a URL-friendly slug from a given string, but you might need them for other purposes. The str_replace() function accepts ...

⌛ 3 min read

PHP double question marks (Null coalescing operator) explained

⤳ PHP double question marks (??) – officially known as Null coalescing operator – is a convenient alternative to ternary expressions in conjunction with isset(). You might have seen the following expression in your Laravel or PHP projects: But what do two question marks mean in PHP? ...

⌛ 2 min read