Learn about the two ways to wait until a DOM element exists before executing a JavaScript function.
Category: JavaScript
How to Check If a Function Exists in JavaScript
Learn how to check if a function exists or not using the typeof operator in JavaScript.
How to Remove Numbers From a String With RegEx
This tutorial will teach you how to match and remove all the numbers in a string using RegEx.
How to Check If a String Is a Number in JavaScript
Learn about the three best ways to check if a string is a number in JavaScript, and when to use each.
How to Link to JavaScript in HTML
Learn the ins and outs of linking to JavaScript script files from your HTML documents.
How to Call a JavaScript Function in HTML
Everything you need to know about calling JavaScript functions in an HTML document—incl. placement, async/defer, and sync.
How to Check If an Object Is Empty in JavaScript
Learn three ways to check if an object is empty in JavaScript.
Redirect to URL With Parameters in JavaScript
This tutorial will teach you how to redirect the user to a new URL while preserving and/or adding URL parameters.
How to Get the Value of Text Input in JavaScript
Learn how to get the value of one or multiple text input fields in JavaScript, with annotated code samples.
How to Add an Element to the DOM in JavaScript
Learn how to add DOM elements to an HTML document with confidence using pure JavaScript.
Getting the Parent of an Element in JavaScript
Learn how to get the parent of a DOM element in JavaScript, and which unreliable methods to avoid.
JavaScript Function With an Optional Parameter
Learn the two best ways to declare a JavaScript function with an optional parameter (and how to give the optional parameter a default value).
How to Find Objects in Arrays With JavaScript
Learn how to find objects within arrays of objects in JavaScript, and how to reference their properties the right way.
How to Store Objects in JavaScript Arrays
Learn how to store a JavaScript object in an array — and how to reference that object or its individual properties in that array.
How to Generate a Random String With JavaScript
Learn about the three best ways to generate a random string with JavaScript, and in which situation to use each.
Check If an Array Contains a Value in JavaScript
Learn about the four best ways to check if an array contains a given value in JavaScript, with code samples.
How to Get the Port Number in JavaScript
Learn about the fastest and most practical way to get the port number of the current URL in JavaScript, without the B.S.
How to Get the Current URL in JavaScript
Learn how to get the current URL of the web page, with or without URL parameters and URL fragments.
How to Create a 2D Array in JavaScript
Learn how to create a multi-dimensional array in JavaScript, and how to reference the items in it for your web app’s needs.
Remove an Element From an Array in JavaScript
Not sure how to remove an item from an array in JavaScript? We’ll walk you through the best methods and help you pick the right one for you.
The Developer’s Guide to localStorage
Learn the ins and outs of localStorage, the persistent Storage object that you can use for storing data in the browser.
The Developer’s Guide to sessionStorage
Learn the ins and outs of sessionStorage, the session-scoped Storage object that you can use for temporarily storing data in the browser.
How to Comment Out JavaScript
Learn how to comment out JavaScript code, what to watch out for, and how to prevent it from slowing down your website or app.
How to Loop Through an Array in JavaScript
Look for the best ways to loop through arrays in JavaScript? Learn the ins and outs of for, while, forEach, map, and for…of loops.
How to Format the Date in JavaScript
Learn how to format the date and how to show the date without the time with just a couple of lines of code in vanilla JavaScript.
How to Create a Multiline String in JavaScript
Need to create a multi-line string in your JavaScript code? Not sure how exactly to do that? We’ll walk you over the three best ways.
How to Set Cookies With JavaScript
Ready to become a JavaScript cookie monster? Let’s get those cookies set and show the browser who’s boss.
How to Start Learning JavaScript
Start your coding journey off on the right foot by learning the basics of JavaScript. Check out our latest article on where to begin.
Convert Node List to Array in JavaScript
Learn how to convert a NodeList object to an Array in this no-B.S. tutorial.
How to Get Today’s Date in JavaScript
Not sure how to get today’s date and time in JavaScript? This guide will walk you through the process step by step and with code samples.
Troubleshoot Unexpected Identifier Errors in JavaScript
No, you’re not trying to solve the unsolvable. Here’s how to handle unexpected identifier errors in your JavaScript code.
How to Calculate String Length in JavaScript
Calculating a string’s length in JavaScript, for beginners. Everything you need to know (and nothing you don’t).
How to Calculate Tax With JavaScript
The best way to calculate tax with JavaScript (and the pitfalls to watch out for as you do).
How to Iterate Over a Map Object in JavaScript
Are you stuck? Don’t worry, we’ve got you. We’ll show you how to iterate over a map object in JavaScript like a pro.
How to Get an Object’s Class Name in JavaScript
You might not know this, but JavaScript isn’t a class-based programming language as other languages are. So let’s talk about your options.
Check If a String Contains a Substring in JavaScript
Does your string contain ___? There’s a simple way to check. Here’s how to search strings for substrings like a pro.
How to Check If a Variable Is/Is Not Null in JavaScript
Not quite sure how to check if a variable is (or isn’t) null in JavaScript? Don’t worry, we got you. This guide will show you the ropes.
How to Convert Map to Array in JavaScript
This tutorial will show you how to convert a Map object’s keys, values, or key/value pairs to an Array object in JavaScript.
Declare vs. Assign in JavaScript
What’s the difference between declaring a constant or variable and assigning it a value? Here’s everything you need to know.
How to Get URL Parameters in JavaScript
How to get all or one of the parameters from the URL of the current page in JavaScript with vanilla JavaScript.
How to Get the Page Path in JavaScript
This tutorial will show you how to get the current page path in JavaScript (and more).
How to Get the Current Domain Name in JavaScript
This tutorial will show you how to get the current domain name in JavaScript (and more).
How to Declare a Global Variable in JavaScript
The two ways to declare a global variable in JavaScript, inside and outside of a function.
Remove Special Characters From a String in JavaScript
Remove special characters from any string with the String.replace() method and well-written RegEx. We show you how!
What Is a Data Layer?
A web developer’s introduction to the data layer, a must-have for advertising and marketing on websites and web applications.
Event Listeners for Multiple Elements in JavaScript
Here’s how to add an event listener for multiple DOM elements in JavaScript.
How to Get the Href of a Clicked Link in JavaScript
Learn how to get the href attribute of any, or specific, clicked links in JavaScript.
How to Get the Class of a Clicked Element in JavaScript
Learn how to get the class of any, or specific, DOM element that the user clicks by creating an event listener.
How to Get the ID of a Clicked Element in JavaScript
Learn how to get the id of any, or specific, DOM element that the user clicks by creating an event listener.
Array to String Without Commas in JavaScript
How to convert an array into a string without commas with the Array.join() method in JavaScript.
How to Run JavaScript on a Mac (4 Ways)
Want to run JavaScript code on your Mac? Here’s how to do it in the Terminal and from your browser.
Removing All Commas From a String in JavaScript
So you need to remove commas from a string in JavaScript? These are the two best ways to achieve this.
Create an Array of Images in JavaScript (Tutorial)
The best ways to create and use arrays of images in JavaScript.
Check If a Button Is Clicked in JavaScript
This is the best way to listen to click events for a button element.
Is Inline JavaScript Bad?
Wondering whether to inline your JavaScript code or load it externally from a file? We help you decide.
Why Is My JavaScript Not Working? (With Examples)
We round up the most common causes for your JavaScript code not working.
Log the User Out on Closing the Browser in JavaScript
Want to log out your user after they’ve closed the tab or window? Here’s how you could do this in JavaScript.
Set an Attribute Without a Value in JavaScript
The best ways to set an empty attribute to one or multiple DOM elements in your HTML markup, with plain JavaScript.
Remove Quotes From String in JavaScript
We look at the simplest, most straightforward way to remove quotes from a string in JavaScript.
Pass PHP Array to JavaScript (Tutorial)
It turns out you can get PHP and JavaScript to agree on something, and that something is the JSON data format.
Nested Arrays in JavaScript, Explained
You asked for it, we delivered. We explain nested arrays in a way that anyone, from beginner to expert, can understand.
How to Declare an Empty Array in JavaScript
Here’s how to declare an empty array object in JavaScript—and what you need to do so that it meets your needs.
Function Not Defined in JavaScript (How to Fix It)
ReferenceErrors are annoying. These common mistakes and clues to look for will help you get to the meat of it.
Alphabet Array in JavaScript (Tutorial)
The simplest, most straightforward ways to create an array of letters in the English alphabet in JavaScript.
Find the Largest Number in an Array in JavaScript
The quick and easy way to find the largest number in an array in JavaScript.
Quotes Within Quotes Within Quotes in JavaScript
There’s a way to nest string in two or more quotes in JavaScript, and you will love the simplicity of it.
Adding a New Line in JavaScript (Tutorial)
Still learning? These are the best ways to add a new line to your JavaScript code’s output.
How to Repeat a String in JavaScript (Tutorial)
In JavaScript, it’s easier to repeat a string an n number of times than you probably think. Here’s how to do it.
Check If an Element Has a Class in JavaScript
So you’re looking for a good way to check if a DOM element has a CSS class in JavaScript?
Check If String Is Empty in JavaScript
Find out the two best ways to check whether a string is empty or not in JavaScript.