I recently did a technical job interview that was for a frontend position. It was for a company that specialised in cybersecurity technologies, but they were looking for React developers to create better UI dashboards for clients.
My first thought right away was, how simple must their codebase be?! I thought the company was looking for React devs! I now see that they were looking for competent Frontend Engineers, not people who can quickly spin up a Next app and boast about how they understand static generation. They wanted engineers who have mastered the fundamentals. These fundamentals can help solve any complex bug in the JS ecosystem. That's the beauty of being a master of the language.
I was a bit nervous to begin because it might be too basic at this point in my career. Starting with sections that explain what a string is will quickly lose my interest. At this time of writing, however, I am pleasantly surprised with what I read so far.
Below the surface of the machine, the program moves. Without effort, it expands and contracts. In great harmony, electrons scatter and regroup. The forms on the monitor are but ripples on the water. The essence stays invisibly below.
- Master Yuan-Ma, The Book of Programming
2^64 (2 to the power of 64) potential numbers. That equates to approximately 18 quintillion options.
That is a lot. Issues usually arise when dealing with massive numbers. Let's talk about all the grains of sand on our Earth. If we stored that value in a variable, we would still have around ten quintillion bits left to do whatever we want.
Some caveats include negative numbers that use an extra bit to signify the
- sign and non-whole numbers like floats. If we consider all of that, we would still have 9 trillion combinations for whole numbers. Unfortunately, not enough to store all the grains of sand...
We have unary operators, rather than just binary operators. A binary operator would be something like
5 + 3, where the plus symbol takes two values. A unary operator takes one value; hence the name.
typeof is a unary operator that returns the value type.
There's only one ternary operator called the conditional operator. You might have seen it before:
true ? 1 : 2.
undefined are peculiar types. The author says they are used interchangeably and are more or less the same thing. I can't entirely agree, as I see
undefined as values that could exist later, whilst null symbolises the value's absence. I'd instead stick to just using undefined if I can, but it's always best to secure your types wherever possible. The author also mentioned that:
Exploring that a little bit, I found this quote on a Stack Overflow post explaining a bit more about the accident.
- Captain Sensible (great name)
console.log(8 * null); // → 0 (null is converted to 0) console.log('5' - 1); // → 4 ('5' becomes 5) console.log('5' + 1); // → 51 (1 becomes '1') console.log('five' * 2); // → NaN (can't use *, /, or - on strings) console.log(false == 0); // → true (false becomes 0)
A neat tip is if you ever find yourself with
NaN errors, keep in mind that further arithmetic operations on
NaN keep producing
NaN, so look where you might be doing any accidental type conversions.
It's also best to use the strict equal operator
=== as that allows you to precisely test for equal values and avoids automatic type conversion.
That's it! As I get into the groove of writing these chapter recaps, I'll hopefully also learn to connect my notes. Currently, it's a little bit all over the place. I do hope you might've learned at least one thing. If anything was confusing here, please let me know, and I can try to explain further. Otherwise, you can check out chapter one on the author's website here.
The next chapter focuses on Program Structure. We just learned about the nails; let's master swinging the hammer.
Originally posted on my personal website, which can be found at alex.kharo.uk.