My Thoughts
I've skimmed through many parts of this book and have put it down many times, but this time I am determined to finish it. I feel like I've plateaued with JavaScript, but as a junior, I know that's not true. There will always be new things to learn about code.
Despite having built several projects in JavaScript and even React, I am still learning new things, even in the early chapters of this book.
So far, i've made it to chapter 4. I find myself skimming through many of the basics of JavaScript like data types, operators, functions, loops, control flow, and scope. Still, it's good to review these. It's a good skill to be able to talk through the basics in interviews. The book even mentions closures in chapter 3!
Highlights from this week's readings
Recursive functions are functions that call themselves.
function power(base, exponent) {
if (exponent == 0) {
return 1
} else {
return base * power(base, exponent - 1)
}
}
from page 50
It took a while for me to wrap my head around this concept. After doing some exercises, it appears that these functions usually return a value in addition to calling the original function with modified arguments. This way, you can code your function to run a certain number of times or until a certain condition is reached.
I also was reminded of a more succinct way to loop through arrays with for loops:
for (variable of iterable) {// do stuff}
I don't know how I went this long without knowing these, but I also was reminded about array.shift()
and array.unshift()
, which affect the first element of arrays. The wording is a little confusing, however. Push and pop were easier to visualize in my head.
What I learned from the Exercises
I steamrolled through the exercises of chapters 1-3. Easy. Somehow though, the difficulty spiked at the end of chapter 4. Some of the solutions were handling loops and arrays in ways I didn't know were possible. It was pretty cool and humbling to see such elegant solutions in comparison to my occasional spaghetti (but we've all been there, right?).
function reverseArrayInPlace(array) {
for (let i = 0; i < Math.floor(array.length / 2); i++) {
let old = array[i];
array[i] = array[array.length - 1 - i];
array[array.length - 1 - i] = old;
}
return array;
}
This exercise was a challenge. I'm used to creating new arrays for these types of problems, but this problem required you to reverse the original array. I tried combinations of push, pop, shift, and unshift combined with for loops. But I overlooked modifying the original array directly.
I learned a couple new things from analyzing this solution:
- Indexing an array and storing it in a variable stores a value, not a reference.
- I'm so used to writing
for (let i = 0; i < array.length; i++)
that I forgot you don't have to follow this exact structure when looping through an array. - Thank goodness for
Array.prototype.reverse()
.
Closing Thoughts
It's helpful getting back into the flow of coding regularly again. This endless job hunt is making me lose sight of how fun it is to solve problems and code. It also feels really good to review the basics. I definitely want to ace the next interview that asks me about JavaScript.
Top comments (0)