Table of Contents
This updated guide examines 9 Popular Javascript Interview Questions and organizes the essential facts, background, and practical takeaways in clear American English.

If you've missed 'fell in love' and intend to find a job that is related to this language, you will definitely need to review the following issues to be confident in showing your abilities and knowledge. I am in front of employers. The more you master the knowledge, overcome the interview questions easily, the higher your chances of getting and good wages will be correspondingly high. Let's take a look at the common issues in JavaScript interviews via TipsMake.com's general article below.
Part 1: The difficult question
Your interview will be 'difficult to chew' if one of the following questions appears unexpectedly
1. Why Math.max () is smaller than Math.min ()
In fact, when runningMath.max() > Math.min(), the return value isFalse, which sounds unreasonable. However, if no parameters are passed, Math.min () returns Infinity and Math.max () returns -Infinity. SoMath.max()< Math.min().
Follow the following code:
Math.min(1) // 1 Math.min(1, infinity) // 1 Math.min(1, -infinity) // -infinity
If-infinityappears as the parameter ofMath.min(), the result will definitely be-infinitymatter how many parameters. Meanwhile, if the parameter appears to beinfinityand some other, the result returned will be that value.
2. Why do the calculations return false results? 0.1 + 0.2 is not equal to 0.3.
This issue involves Javascript storing float data in binary form to exactly one digit after the comma. If you enter the following program into the control panel, you will see the following result:
0.1 + 0.2 // 0.30000000000000004 0.1 + 0.2 - 0.2 // 0.10000000000000003 0.1 + 0.7 // 0.7999999999999999
Of course this will not cause any big problems if you only implement simple equations that do not need high precision. However, it will cause headaches if you want to check for equality between objects.
There are several solutions to this problem:
Fixed Point - Fixed point
Use when you know the maximum accuracy you need, the number of digits after the comma is fixed.
For example, you are trading with a currency, enter an integer to store the value, instead of entering $ 4.99, enter 499 and perform calculations on this number. After finishing the session with it, you can display the results to the end user using an expression like this:
result = (value / 100).toFixed(2)
to return the result string as desired.
Binary Coded Decimal - Binary Coded Decimal Numbers
If the accuracy in your equation is very important, use this Binary Coded Decimals (BCD) format by accessing the BCD library right in JavaScript. Each decimal value is stored separately in a single byte (8 bits). This obviously wastes a lot of bits, but it makes translating into a string that can be read much easier than the traditional binary to decimal conversion. It may also not be the best, because 1 byte can store as many as 16 separate values while the system uses only 0-9 values. So as initially stated, if your application prioritizes accuracy, use this solution, it's worth a little bit of a trade.
3. Why 018 subtracts 017 by 3?
018 - 017returns3as the result of silent type conversion. In this case we are referring to octal number.
Quick introduction to octal numbers
You can listen to and use a lot of binary number systems (base 2) and hexadecimal (base 16) in computing, but you may hear less about octal systems (base 8) even though This system also has a prominent position in computer history. In the 1950s and 1960s, the octal system was used for binary abbreviations, helping to cut material costs in expensive systems for manufacturing.
Octal system today
The octal system has an advantage over hexadecimal in some cases because it does not require any letters to represent any number (use 0-7 instead of 0-F).
Returning to the question, in JavaScript, prefix 0 will convert any number to octal numbers. However, 8 does not exist in the octal and the number containing the digit 8 will be converted implicitly into a normal decimal.
Therefore,018 - 017actually equivalent to the decimal expression017, since017is an octal,018is a decimal, so017also converted to the corresponding decimal number 15. So the answer is This is3.
Part 2: Frequently asked questions
In this section, Tipsmake will mention more popular interview questions. This is usually the knowledge you easily overlook when you get used to JavaScript from the beginning, but they are all very useful and can help you write better code later.
4. Difference between Function Declaration and Function Expression
Function declaration uses function keyword and function name. And Function expression starts withvar,letorconst, followed by the name of the function and the operator=.
Here are some examples:
// Function Declaration function sum(x, y) { return x + y; }; // Function Expression: ES5 var sum = function(x, y) { return x + y; }; // Function Expression: ES6+ const sum = (x, y) => { return x + y };
How to use, Function declaration, you can call before declaring or after declaring it all, while the function expression must have a sequence.
The function declaration is moved to the beginning of scope by the JavaScript interpreter and can be called before the declaration or after the declaration is made, call it anywhere in your code. Conversely, calling Function expression must have a sequence: it must be declared before it can be called.
The function expression today is a bit more popular by developers because of several reasons like this:
- The function expression implements structured codebase, easy to follow and predict.
- It is possible to use a more concise syntax of ES6 for Function expressions,
letandconstprovide more control over whether a variable can be reassigned or not.
5. What is the difference between var, let and const?
This is a quite popular interview question since ES6 was released because of the high possibility that recruitment agencies have also used the more modern syntax in this new version.
varis the variable declaration keyword that appears right from the first release of JavaScript version. However, it has several disadvantages that lead to the development of two new keywords in ES6 laterletandconst.
These three keywords have different approaches related to assignment, hoisting and scope. Let's go to each part separately.
a.Assignment
The most fundamental difference is thatletandvarcan be accessed again whileconstis not possible. This makesconstthe best choice for constant variables, preventing errors if randomly reassigned.
b.Hoisting
Similar to the difference between declarations and expressions function (discussed above), variables usingvarto declare are always placed at the top of their respective scope, that is, regardless of where you declare the variable. In a function, it automatically takes it to the top of the function to declare (javascript automatically implements this concept implicitly). Meanwhile, variables useconstandletto declare a scope in a block code, that is, it will not be affected by the concept of hoisting, but if trying to access these variables before they are declared You will receive a "temporal dead zone" error. Take the following example:
var x = "global scope"; function foo() { var x = "functional scope"; console.log(x); } foo(); // "functional scope" console.log(x); // "global scope"
Here, the results of foo () and console.log (x) are as expected. But what if we leave the secondvar?
var x = "global scope"; function foo() { x = "functional scope"; console.log(x); } foo(); // "functional scope" console.log(x); // "functional scope"
Although defined in a function,x = "functional scope"overrides global variables. We need to repeatvarto determine that the second variable x is only within the scope of foo ().
c) Scope
Whilevaroperates in function-scoped,letandconstare block-scoped, a block is all code within curly brackets{}, including functions, command statements event and loop. To illustrate the difference, see the following code:
var a = 0; let b = 0; const c = 0; if (true) { var a = 1; let b = 1; const c = 1; } console.log(a); // 1 console.log(b); // 0 console.log(c); // 0
It can be seen that, within the conditional code block, the variablevar aaccess range is globally re-accessed, butlet bandconst care not
6. What happens if you specify a variable without keywords?
What happens if you define a variable without using any keywords? Technically, ifxnot defined, thenx = 1is an abbreviation forwindow.x = 1, but this is a common cause of memory leak.
To prevent this problem, using strict mode, this mode requires you to explicitly declare everything to avoid potential errors. If declaring a variable missing the keyword, the program will display an error:Uncaught SyntaxError: Unexpected indentifier.
7. What is the difference between Object Oriented Programming (OOP) and Functional Programming (FP)?
JavaScript is a multi-model language, which means it supports many different programming styles, including event-oriented, functional, and object-oriented.
There are many different programming models, but in contemporary computing, two of the most popular styles are Functional Programming (FP) and Object Oriented Programming (OOP) - JavaScript can do both.
a.Object-oriented programming
OOP is based on the concept of "object". These are data structures that contain known data fields in JavaScript as "attributes" - and procedures called "methods".
Some objects built into JavaScript can be included asMath(using methods likerandom,max,sin.),JSON(used to analyzeJSONdata) or data types such asString,Array,NumberandBoolean.
Basically, whenever you use built-in methods, prototypes or classes, you are using object-oriented programming.
b.Functional programming
There are many functional programming models built into JavaScript like thehigher-orderfunction. This is a function that can take another function as an argument.
In addition, JavaScript also has some functions that work with arrays such asmap(),reduce(),filter(). all arehigher-orderfunctions. This means you can string them together to quickly implement the methods in an array.
Although JavaScript initially had some problems with transformability, newer versions of the ECMAScript standard provided fixes. Instead of using thevarkeyword to define variables, you can useconstandlet. The first keyword allows you to define constants as implied names. The second keywordlet, limits the scope of a variable in the function it declares.
8. The difference between Imperative programming and Declarative programming
You can rely on the difference between OOP and FP to answer this question about imperative programming and declarative programming.
These are terms that describe common characteristics between many different programming models. FP is an example of declarative programming, while OOP is an example of imperative programming.
It can be envisioned that with Imperative Programming you are interested in how to solve the problem, go step by step in the most essential way, characterized byfor,whileloops,if,switch.
const sumArray = array => { let result = 0; for (let i = 0; i< array.length; i++) { result += array[i] }; return result; }
In contrast, Declarative Programming is concerned with the input and output of the problem. This often leads to more concise code, but only at a certain scale, but it can become more difficult to debug because it is not explicit.
The declaration example for sumArray () function above.
const sumArray = array => { return array.reduce((x, y) => x + y) };
9. What is prototype-based inheritance (Prototype-Based Inheritance)?
There are a number of different object-oriented programming types and JavaScript uses prototype-based mechanism inheritance. The system that allows inherited behavior through the use of existing objects serves as the prototype.
Note, even if you have not heard about prototypes, you certainly have encountered a prototype system using the in-built methods.
For example, functions used to manipulate arrays such asmap,less,splice. are methods ofArray.prototypeobject. In fact, every instance object of the array (defined by square brackets[]or usingArray()) inherits from Array.prototype, which is why methods likemap,reduceandspliceDefault available.
This is similar to almost any other built-in object, such as string and boolean (exceptInfinity,NaN,nullandundefinedno properties or methods).
At the end of the prototype string, we will findObject.prototypeand almost all objects in JavaScript are an instance ofObject.prototype. For example,Array.prototypeandString.prototypeboth inherit properties and methods fromObject.prototype.
To add properties and methods to an object with prototype syntax, you simply initialize the object as a function and use the prototype keyword to add properties and methods:
function Person() {}; Person.prototype.forename = "John"; Person.prototype.surname = "Smith";
In this article, TipsMake.com introduced you to some of the issues that employers often ask to check out a JavaScript developer. The actual interview questions may be different but basically the issues will be similar and revolve around these contents. If you can't answer all the questions, don't worry, try to read a lot, do a lot, find out, Tipsmake is sure you can do well.
If you have any interesting questions related to article content: JavaScript developer interviews, share them in the comments section, this will be helpful for many others.
Thank you for following the article. Good luck!
FAQ
What is 9 Popular Javascript Interview Questions about?
It provides a structured overview of javascript interview, explains the main context, and highlights practical takeaways for readers.
Why does this topic matter?
Understanding the main concepts helps readers evaluate the issue, avoid common mistakes, and make better-informed decisions.
How should readers use this information?
Use the guidance as a practical starting point, confirm details that may have changed, and follow current product, safety, or security recommendations.
Reader Comments 0
Sign in with email or Google to join the discussion.