JavaScript the most popular language on the web, is fully natively supported by browse and nowadays is a very important tool for a front-end web developer.
Tools like React, Vue, Angular are created on top of JavaScript, so if you are looking for a job as a Front End Developer you may know that is very important to have a clear understanding of what is Javascript.
You don't be surprised if interviewer/recruiter do some question about Javascript, it's totally normal...
So let's see some of that's questions...
What is DOM?
When the browser tries to render a HTML document, it creates an object based on the HTML document called DOM (Document Object Mode).
What is a closure?
A closure is a function having access to the parent scope, even after the parent function has closed.
Event delegation
Event delegation is a technique in JavaScript where you attach a single event listener to a parent element to manage all the events that happen inside it, instead of attaching individual event listeners to each child element.
Event propagation
Event propagation is a mechanism that defines how events propagate or travel through the DOM tree to arrive at its target and what happens to it afterward.
Event bubbling
During the event propagation process, an event first triggers on the target element and then bubbles up through its ancestors in the DOM tree.
"target" vs "currentTarget"
Difference is that target
is the actual thing that was clicked and currentTarget
is who you attach to the event listener.
Explain IIFE
Immediately Invoked Function Expression, that's mean, I write that function and I run.
Explain "hoisting"?
In simple words variable can be used before it has been declared, all variables var
are declared at the top of any function scope.
Function.prototype.bind()
Creates a new function that, when called, has its this
keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.
const vs let vs var
Before the ES6 version of JavaScript, only the keyword var
was used to declare variables.
const
: Block-scoped, cannot be reassigned after declaration.let
: Block-scoped, can be reassigned after declaration.var
: Function-scoped, hoisted to the top of its function or global scope, can be reassigned, and not block-scoped.
null vs undefined
The undefined
is declared but doesn't have a value and null
is a "nothing" value.
== vs ===
Difference is that ==
checks for equality and ===
checks for equality and type.
map vs forEach
The forEach()
executes a provided function once for each array element and map()
creates a new array with the results of calling a provided function on every element in the calling array.
Example of forEach
:
Example of map
:
Synchronous vs Asynchronous
The synchronous waits for each operation to complete, after that only it executes the next operation, asynchronous never waits for each operation to complete, rather it executes all operations in the first GO only.
In synchronous code, each operation blocks the execution until it's complete.
Output will be in the same order as the code: 1, 2, 3.
In asynchronous code with callbacks, the setTimeout function doesn't block the subsequent code.
Output: 1, 3, 2 (after 1 second).
What is a Promise?
A promise is an object which can be returned synchronously from an asynchronous function.
Higher order function?
Is a function that takes a function as an argument, or returns a function, for example map
, filter
, reduce
...
Conclusion
In my point of view, I don't care much if the developer knows the theory, but it is very important if he knows what to use and when to use it.
Of course, if we are using a lot of tools like React
, many of these things are non-transparent, but it is always good to understand what is done behind all of the magic.