Currently browsing Methods, Events and Scopes

Tuesday, June 18, 2024

Simplifying Conditional Statements in JavaScript with the && Operator

JavaScript provides several ways to handle conditional logic. One powerful method is the logical AND (&&) operator. This tutorial will…

Wednesday, July 12, 2023

A collection of modern native JavaScript object and array utilities

Arrays Chunk Creates an array of elements split into groups the length of size. Compact Creates an array with all…

Monday, August 29, 2022

Code Golfing Tips & Tricks: How to Minify your JavaScript Code

JavaScript golfing is the process of writing the smallest amount of JavaScript code to do something awesome.

Tuesday, August 9, 2022

The Complete JavaScript Strings Reference

JavaScript strings are deceptively complex constructs. There are actually two different types of strings – string Literals and string Objects…

Monday, July 4, 2022

JavaScript Form Validation

This JavaScript code snippet adds inline validation to any form field (input, select and textarea). Feel free to customise it…

Tuesday, May 17, 2022

How to Optimize a Theoretical Funnel Page Load Speed

Here’s a quick snippet to preload the next step in a theoretical funnel/workflow: PHP JavaScript Like0

Tuesday, December 27, 2022

Numerical Integration Using JavaScript

This is a quick reminder on how to use mathematical functions inside JavaScript. Instructions Trig: sin, cos, tan, cot, sec,…

Tuesday, May 17, 2022

Random JavaScript Tutorials

I needed some structural updates for a site, and among them, I added some JavaScript snippets. I will show you…

Wednesday, April 30, 2025

How to Declare a Global Variable inside a JavaScript Function

A JavaScript global variable is a variable with global scope, meaning that it is visible and accessible throughout the program, unless…

Friday, June 3, 2022

How to execute code for X visits

This JavaScript will let you execute code a certain number of times. For example, you might want to only show…

Friday, June 3, 2022

JavaScript shortcuts for TRUE and FALSE

Here’s a neat trick if you’re into micro-optimization. JavaScript compressors and minifiers are used to make JavaScript code smaller and,…

Thursday, January 30, 2025

How to Expire localStorage Items and Replace Cookies

I don’t use 🍪 cookies any more, I think they are too… rigid. I use localStorage items. By default, they…

Monday, May 16, 2022

How to extract a value from an element and, optionally, round it

This JavaScript snippet will extract a price from a DOM element, remove all alphanumeric characters, such as currency or symbols…

Tuesday, May 17, 2022

How to create a YouTube video cover using the YouTube Iframe API

There’s an increasing trend of adding full-width (possibly full-height) YouTube video covers with autoplay. Using the YouTube Iframe API, this…

Monday, May 16, 2022

How to Get and Set URL Parameters with JavaScript

This is an old script, which helped a lot with the initial phase launching a project on all browsers and…

Monday, May 16, 2022

How to Implement a Service Worker in Your Website and How to Create a Basic PWA

You definitely don’t need a plugin for this. Although there are plugins which help with creating a service worker and…

Monday, May 16, 2022

Cross-browser Query Parameter Getter and Setter

Here’s a cross-browser compatible way of getting query parameter from a URL or setting query parameters and reloading the page. An…

Monday, May 16, 2022

How to Autoplay a Video Element Using JavaScript

The latest Chrome version has stopped video autoplay if the video is not muted. Firefox and the other browsers will soon…

Monday, June 12, 2023

JavaScript Data Types

Every variable in JavaScript has a data type which dictates the values that can be stored in it. However, JavaScript…

Monday, May 16, 2022

How to Compare Version Numbers in JavaScript

The basic idea to make this comparison would be to get arrays of parts from the version numbers and then compare pairs…

Monday, May 16, 2022

Useful JavaScript String Prototypes

This is a function to remove all double whitespaces and preceding line breaks. This is a function to replace all line…

Monday, May 16, 2022

truthy and falsy in JavaScript

In JavaScript, any variable can be used in a logical context, such as the condition of an if statement or…

Wednesday, June 15, 2022

Promises in JavaScript

Writing code in an async programming framework like node.js becomes super complex and unbearably ugly, superfast. You are dealing with…

Monday, February 27, 2023

Custom Events in JavaScript MVC

Events are the bread and butter in UI development. They are frequently used to kick off JavaScript to deal with…

Tuesday, May 10, 2022

Cutting Loose: Dynamic Namespacing in JavaScript

Most of the JavaScript libraries come wrapped in an easy to refer single object. The object acts as a namespace,…

Tuesday, May 10, 2022

Understanding JavaScript Currying

I recently fully understood the concept of utilizing Currying in JavaScript. The core concept can be grasped from these references: Wikipedia entry on…

Wednesday, April 30, 2025

John Resig’s Inheritance

John Resig, the creator of jQuery, has created this JavaScript inheritance code. I am still using it now to simplify several…

Tuesday, May 10, 2022

Encapsulation: Private Attribute

In JavaScript OOP there are attributes called private attributes. Knowing if an attribute is private or public, an API user…

Wednesday, April 30, 2025

Encapsulation: Private and Public Methods

When it comes to developing APIs, self-documenting code is very important, as it simplifies the user’s effort in filtering the…

Tuesday, May 10, 2022

Giving Object Context to Function Calls

JavaScript has a dynamic object named this. By default, this equals to the global object container, so if we have…

Tuesday, May 10, 2022

Use ‘this’ Keyword with setTimeout()

setTimeout() is a great help to many JavaScript developers. For example, you may wish to add a delay to allow…

Wednesday, April 30, 2025

JavaScript String Multiline Trim/Cleanup

This small JavaScript prototypes enhance the trim() function and allow for better trimming and/or replacing line breaks with commas (or…

Tuesday, May 17, 2022

How to Open a JavaScript Centered Popup Window

This tutorial is about JavaScript popups and how to show a window in the center of the screen and focus on it.…