I believe that one of the first and foremost reasons people struggle to understand hoisting is because the term itself is somewhat misleading. The Merriam-Webster definition of the word hoist is “an act of raising or lifting”.
This might lead one to assume that hoisting involves written code being physically rearranged somehow. This is not true.
Instead, the term hoisting is used as a kind of simile to describe a process that occurs while the JavaScript engine interprets written JavaScript code.
All written JavaScript is interpreted within the Execution Context that it is written in. When you open up your…
I recently built an etch-a-sketch variant as an exercise for practicing basic JavaScript, CSS, and HTML. I wanted to document my experience in order to strengthen my understanding of what I built and to avoid the “I don’t know how it works, but it works!” perspective. I’d also love to hear any feedback!
I started with a basic HTML skeleton:
I then filled in this HTML skeleton with what I felt my project would need:
I wanted to have my “Etch-A-Sketch” grid take up the right half of my page with the title and interactive elements sitting on…
You know them, you love them, and you probably use them all the time! Introduced as part of the ECMAScript 6 update in 2015, arrow functions exploded in popularity, and with good reason. Arrow function syntax is wonderful syntactic sugar that removed the need for the following:
Arrow functions also reduced some of the complexity involved in JavaScript function scope, as well as the this
keyword, because sometimes all you really need is an anonymous function.
All that being said, arrow functions are not a one-size-fits-all solution for…
In computer science, the type of structures that we constantly build and use are called data structures.
A data structure is a storage format created for the purpose of storing and organizing data, often prioritizing the accessibility and customization of that data. In other words:
“More precisely, a data structure is a collection of data values, the relationships among them, and the functions or operations that can be applied to the data.” -Wikipedia
JavaScript has two built-in data structures: arrays and objects.
“The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or…
Unlike Java or C#, JavaScript is a loosely typed language, which makes it a very forgiving language. To the best of its ability, JavaScript will try to cover for most mistakes made by those who write it.
On the surface, this may seem like a good thing, but it can allow for some rule-bending that often leads to unintended consequences down the line. This has earned the default JavaScript environment the title of sloppy mode.*
Not an official title, but MDN does have a page dedicated to the term.
Is avoiding slop enough reason to employ strict mode? Only you…
JavaScript has several different types of operators. These include comparison, arithmetic, logical, and many more.
These operators can be further defined as either unary or binary. Let’s break down the difference between these two terms now as we move toward understanding ternary.
A unary operator takes just one operand, either before or after the operator:
operator operand || operand operatorfor example:x++ || ++x
A binary operator requires two operands, the most common examples being basic addition, subtraction, multiplication, and division:
operand operator operandx + y; || x - y; || x * y; || x / y;
…
Undeclared is not a JavaScript reserved word. This means we don’t use or assign undeclared
when writing code, instead, we encounter the error message that is produced when we try to use an undeclared variable.
aVariable;
console.log(aVariable) // ReferenceError: aVariable is not defined
When we try to use a variable that has not been declared using either of the keywords let
or const
, this usage will result in the above error message.
Ironically, this error message reveals the first slightly confusing scenario we’re looking at today: the data type of an undeclared variable is undefined
.
undefined
is one of seven…
As you likely already know, there are a variety of ways to convert a string to an integer in JavaScript. However, it’s up for debate as to which method is the “best” method available to developers. Let’s take a look at some options.
parseInt(string, radix)
We begin with parseInt()
which takes two arguments, a string and a radix. The function returns an integer parsed from the given string.
If the first argument is not a string, it is converted to one automatically using ToString()
. Either way, any leading whitespace is ignored.
The parseInt()
method starts at position 0 and determines…
As human beings, we’re genetically programmed to anthropomorphize. To anthropomorphize is “to attribute human form or personality to things not human.” It’s a complicated, not entirely understood instinct that may have helped our ancestors spot familiar friends or hidden enemies. This is part of why we see silly faces in the clouds and spooky faces in the dark.
Unfortunately, for some of us (including yours truly), this means that when struggling to learn a new subject, we can subconsciously humanize said subject. When I struggle with code, I start to think of code as an enemy, as something that’s out…
These days, I am actively applying to and interviewing for jobs. Maybe you are too, dear reader.
A few days ago, I had an interview in which the engineering team asked me to explain what a closure is. It’s certainly not the first time that I’ve been asked about the term, but I’m not going to lie, I panicked a bit.
Closures have developed something of an infamous reputation for being an impossibly difficult screening question.
After the interview, I was frustrated that the topic was still daunting to me. I was determined to buckle down and defeat closure once…
Web Developer, writer, bookworm, viewer of indie films. Passionate about problem-solving and building a more equitable -and joyful- world. Actively job seeking.