The latest technology and digital news on the web

Insightful takes on ascent your business

Here are the 20 JavaScript questions you’ll be asked in your next interview

Live Code Stream
Story by
Live Code Stream

An interview is an important part of the hiring process. It gives insights about the skillset, knowledge, and the adeptness of an alone to take on arduous tasks. It’s also one of the most reliable ways for an employer to filter out clashing candidates for a job posting.

As a JavaScript developer, you must adapt yourself before actualization in an exam or an interview. It’ll access your affairs of accepting hired by a accounted company.

Now, you might be apprehensive where to start when it comes to alertness and accepting accustomed with the kind of questions that’ll be thrown your way. So, to help you out, I’ve accumulated a list of frequently asked JavaScript account questions. Each of these questions has a brief answer which you can review below.

In the end, you’ll be a bit more able and assured to answer any catechism your accuser may ask. So, let’s get started.

First of all, what is JavaScript?

JavaScript is a scripting accent created by Netscape in 1995. It was initially used on a accepted web browser called ‘Netscape Navigator. ‘But, these days, we can use it for client-side as well as server-side appliance development.

Well… I don’t think addition will ask this, but we shouldn’t forget where JavaScript comes from.

Can you list some advantages of JavaScript?

  • JavaScript can work offline inside the web browser.
  • It supports assorted programming paradigms. For example, we can make use of Object-Oriented, Functional, and Imperative programming concepts.
  • It has the better accumulating of open source libraries and frameworks.
  • JavaScript is able of creating online and offline games, desktop software, websites, and mobile apps.
  • No need to learn abstracted programming languages to create frontend and backend of a website. JavaScript is accurate on all major web browsers and it can run on the server using Node.js.
  • It is an interpreted language. Acceptation we don’t have to build or abridge its code before use. JavaScript instructions assassinate directly.

Should we use centralized or alien JavaScript?

Internal JavaScript is more acceptable when we just need to use it on a single web page. Whereas, always use an alien JavaScript file for websites that have assorted web pages.

Why do WordPress plugins like Autoptimize accumulated JavaScript Code in one file?

Aggregation of JavaScript source code in a single file reduces the number of requests made to the server while breeding a web page. In turn, it makes a website load faster.

For example, let’s say we’ve included ten JavaScript files on a web page. Now, when we open this web page our web browser sends ten HTTP requests to the server in order to retrieve these files. On the other hand, if we accumulated the code of all these files into one then we just need to make one appeal to the server.

What is JavaScript ‘hoisting?

Hoisting is a abstraction in JavaScript which allows us to use variables and functions even before they are declared.

Basically, when we assassinate a JavaScript code then at first it automatically extracts all capricious and action declarations from the code and moves them to the top of their scope. After that, it starts active the code.

The major account of hoisting is our code works accurately and doesn’t affectation any errors like “undefined variable” or “undefined function.”

Learn more about hoisting with my article ‘Understanding Variables, Scope, and Hoisting in JavaScript.’

Can you adumbrate the output of the afterward code?

Code:

Output:

Juan Cruz Martinez

Explanation:

  • First of all, the capricious acknowledgment at line # 2 and line # 3 will be advised as one statement.
  • Now, the abstraction of hoisting will be applied. Meaning JavaScript will move the capricious acknowledgment to the top. After that, the code will be executed.
  • Also, bethink that the value stored in a capricious will not be lost even if we redeclare the variable.

What is JavaScript ‘Strict Mode’?

The absence behavior of JavaScript is very affectionate in case we make a minor mistake. It means it will not affectation any error messages. But, sometimes in development, we need to see all kinds of errors and warnings to debug the code.

Here comes the use of “Strict Mode” in JavaScript. Basically, it’s a belted alternative where JavaScript displays all errors and warnings, even if they are silent ones.

We can enable “Strict Mode” by using the "use strict"; directive at the alpha of our script.

What are some alternatives to Svelte?

Svelte is a front-end development framework for the JavaScript programming language. Some of its accepted alternatives include:

  • React
  • Vue.js
  • Angular

What are ‘Self Invoking Functions’?

Self Invoking Functions are a little altered from normal functions because they are accomplished anon where they were declared.

Normally, we first acknowledge a action and later just call it. But, JavaScript automatically executes the code of Self Invoking Functions at run-time.

A point to be noted is that these functions do not have any name. In turn, we are unable to recall these types of functions. They are also known as “Anonymous Functions”.

Here’s an archetype of Self Invoking Functions:

What is the aberration amid ‘var,’ ‘let,’ and ‘const’?

Learn more about them in my article ‘Understanding Variables, Scope, and Hoisting in JavaScript.’

What is the aberration amid ‘==’ and ‘===’?

Both of them are used in JavaScript to accomplish a allegory amid two values.

Is there any aberration amid ‘null’ and ‘undefined’ keywords?

Both of these keywords represent an empty value. But, there are two basic differences between null and undefined.

Can you tell the aberration amid ‘function declaration’ and ‘function expression’?

Basically, ‘Function Declaration is annihilation but the normal process of defining a action using the keyword function, its unique name, parameters, and the action body. Whereas, when we assign a function declaration to a variable then it becomes ‘Function Expression.’ It’s absorbing to note that action expressions are not hoisted, meaning, they’ll affectation an error if you try to call them before defining.

Function Declaration:

Function Expression:

What is a ‘Closure’?

A ‘closure’ in JavaScript is a action inside addition function. The inner action has access to its own variables, the variables authentic in the outer action as well as the global variables.

Closure Example:

Can you adumbrate the output of these two functions? And will they return same the output or not?

Output of Action user1()

{name: "Juan"}

Output of Action user2()

undefined

What is ‘NaN’?

In JavaScript, NaN stands for “Not a Number.” It’s a appropriate value that occurs when we’re unable to accomplish an operation.

For example, what if we try to divide a string using a number (e.g. “Hello World” / 5).

Can you explain the for-in loop?

The for-in loop is accurately advised to loop through all the object’s backdrop in a step by step manner. It selects one acreage from the object in each abundance and performs the appropriate operations on it.

Let’s try to accept it with the help of an example:

Output:-

name -> Juan
country -> Germany
website -> livecodestream.dev

What’s ‘Event Bubbling’ and ‘Capturing’?

In JavaScript DOM, HTML elements are nested inside one addition to form a hierarchy.

Now, if both parent and child elements have registered a handle for a specific event then what will be the order of event propagation?

It can be bent in two ways which are known as event bubbles and capturing.

In event bubbling, the child aspect will abduction the event first and then bear it to parent elements. Whereas, in event capturing, the parent aspect will abduction the event first and then bear it to the child elements.

What’s the aberration amid JavaScript and ECMA Script?

JavaScript is a scripting accent admitting ECMA Script is a accumulating of guidelines and rules to assimilate JavaScript across altered web browsers.

In JavaScript, a cookie can be created using a document.cookie object. Simply assign it a string value that is just a series of key-value pairs afar with semi-colons.

JavaScript Create Cookie Example:

Conclusion

Employers usually try to abash the applicants by asking tricky questions. So, if you’re not adorable then affairs are you’ll end up losing the opportunity.

So, today, I tried to answer some frequently asked JavaScript account questions. You may even use it as a advertence just before going to an interview.


This article was originally appear on Live Code Stream by Juan Cruz Martinez (twitter: @bajcmartinez), architect and administrator of Live Code Stream, entrepreneur, developer, author, speaker, and doer of things.

Live Code Stream is also accessible as a free weekly newsletter. Sign up for updates on accumulated accompanying to programming, AI, and computer science in general.

Appear October 14, 2020 — 06:30 UTC

Hottest related news