Basics

48 bookmarks
Newest
Statements Vs. Expressions • Josh W. Comeau
Statements Vs. Expressions • Josh W. Comeau
One of the most foundational things to understand about JavaScript is that programs are made up of statements, and statements have slots for expressions. In this blog post, we'll dig into how these two structures work, and see how building an intuition about this can help us solve practical problems.
·joshwcomeau.com·
Statements Vs. Expressions • Josh W. Comeau
JavaScript forEach() – JS Array For Each Loop Example
JavaScript forEach() – JS Array For Each Loop Example
When working with arrays, there will be times when you need to loop or iterate through the array's values in order to either output or manipulate them. These arrays can hold any datatype, including objects, numbers, strings, and many others. In this article, we'll look at how you can
·freecodecamp.org·
JavaScript forEach() – JS Array For Each Loop Example
Nested Objects in JavaScript
Nested Objects in JavaScript
In today's post, we'll learn what is nested objects and how to create them in JavaScript.
·delftstack.com·
Nested Objects in JavaScript
JavaScript: Restart all Animations of an Element
JavaScript: Restart all Animations of an Element
Recently built a demo that demonstrated a specific animation. Only problem: if you missed it, you had no way of restarting it. Instead of forcing the visitor to reload the page, this little JavaScript-snippet – attached to a button click – did the trick: const restartAnimations = ($el) = { $el.getAnimations().forEach((anim) = { anim.cancel(); anim.play(); … Continue reading "JavaScript: Restart all Animations of an Element"
·bram.us·
JavaScript: Restart all Animations of an Element
Array cheatsheet Javascript
Array cheatsheet Javascript
Variables in Javascript allow only one data to be stored at a time. However, given that it is often...
·dev.to·
Array cheatsheet Javascript
How to create an object from an array of data
How to create an object from an array of data
A few months ago, I saw someone one Twitter ask: Can we create an object by looping on some data 🤔 Today, I wanted to write about how to do just that. Let’s dig in! An example of some data Let’s imagine you got back an array of data from an API service called WizardSchool. It provided you with a list of wizards. Each wizard in the array is itself an object that contains the wizard’s name, and an array of spells that they know how to cast.
·gomakethings.com·
How to create an object from an array of data
Why is JavaScript event delegation better than attaching events to each ele
Why is JavaScript event delegation better than attaching events to each ele
I typically recommend using event delegation for event listeners instead of attaching them to individual elements. Let’s say wanted to listen to clicks on every element with the .sandwich class. You might do this. var sandwiches = document.querySelectorAll('.sandwich'); sandwiches.forEach(function (sandwich) { sandwich.addEventListener('click', function (event) { console.log(sandwich); }, false); }); But with event delegation, you would listen for all clicks on the document and ignore ones on elements without the .
·gomakethings.com·
Why is JavaScript event delegation better than attaching events to each ele
What's the difference between JavaScript event delegation, bubbling, and ca
What's the difference between JavaScript event delegation, bubbling, and ca
Yesterday, I wrote about why event delegation is better than attaching events to specific elements. In response, my buddy Andrew Borstein asked: What’s the difference between event delegation/bubbling/capturing? This is a great question that I get fairly often. The terms are often used interchangeably (sometimes by me, oops!), which can cause some confusion. So let’s clear that up today. tl;dr: event delegation is the technique, bubbling is what the event itself does, and capturing is a way of using event delgation on events that don’t bubble.
·gomakethings.com·
What's the difference between JavaScript event delegation, bubbling, and ca