Preparing for Your JavaScript Interview
The Basics: Technical Questions and Answers
By K.T . Lindemann
Introduction
Today, you cannot be a web developer and not know JavaScript. What started out as a small client side scripting language has evolved into countless frameworks and libraries that are part of every users web experience. All modern web browsers implement the JavaScript language, thus making it the only one deployed on all personal computers and mobile devices around the world.
As it evolved, JavaScript has embraced advanced features such as prototypal inheritance, modules, namespaces, anonymous (lambda) functions, promises, and even metaprogramming. Thanks to frameworks like NodeJs, you can even use it server-side now.
JavaScripts growth presents a challenge for new developers. On the one hand, the barrier to entry is low anyone can open a developer tools window in the web browser and begin to write JavaScript. On the other hand, the level of complexity grows exponentially as you begin to explore the functionality available in the vast JavaScript ecosystem.
Its now common for technical phone screens to include JavaScript questions. As a candidate, where should you begin to study?
While other books tend to focus on the coding part of technical interviews, this book aims to run through some common, foundational JavaScript interview questions that candidates may be asked to explain or describe out loud. Focusing on vanilla JavaScript, this book covers the basics of JavaScript data structures, error handling, UI manipulation, and more! Being able to answer these questions concisely and confidently will go a long way towards making you a better candidate.
Good luck!
Table of Contents
Introduction
Genera l Practice
JavaScript and UI Elements
Compare and Contrast
Bonus Questions
Genera l Practice
This section focuses on the basics of vanilla JavaScript.
Question: What is JavaScript?
JavaScript, often abbreviated as "JS", is a high-level, dynamic, untyped, and interpreted run-time language.
JavaScript is a client-side as well as server side scripting language that can be inserted into HTML pages and is understood by web browsers. JavaScript can also be an Object Oriented Programming language
Question: What are the two basic groups of dataypes in JavaScript?
Primitive types: string, number, boolean, null, undefined
Complex types: object (including functions)
Question: What are the JavaScript types?
There are just six types in JavaScript: Object, Number, String, Boolean, Null, and Undefined.
Objects include arrays, functions, and ordinary objects.
Numbers may be integers or floating point or the special values NaN and Infinity.
Strings include the empty string.
Question: Which company developed JavaScript?
Netscape is the software company who developed JavaScript.
Question: What are undeclared and undefined variables?
Undeclared variables are those that do not exist in a program and are not declared. If the program tries to read the value of an undeclared variable, then a runtime error is encountered.
Undefined variables are those that are declared in the program but have not been given any value. If the program tries to read the value of an undefined variable, an undefined value is returned.
Question: What are global variables?
Global variables are those that are available throughout the length of the code, that is, these have no scope. The var keyword is used to declare a local variable or object. If the var keyword is omitted, a global variable is declared.
The problems that are faced by using global variables are the clash of variable names of local and global scope. Also, it is difficult to debug and test the code that relies on global variables.
Question: What is this keyword in JavaScript?
This keyword refers to the object from where it was called.
Question: What is the use of isNaN function?
isNan function returns true if the argument is not a number otherwise it is false.
Question: What is negative infinity?
Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero.
Question: Which symbol is used for comments in Javascript?
// for Single line comments
/* MultiLine
Comment */
Question: What is the === operator?
=== is called as strict equality operator which returns true when the two operands are having the same value without any type conversion.
Question: What is called Variable typing in Javascript?
Variable typing is used to assign a number to a variable and the same variable can be assigned to a string. This is called variable typing.
Question: Does JavaScript support automatic type conversion?
Yes, JavaScript does support automatic type conversion.
JavaScript is a "loosely typed" language , which means that whenever an operator or statement is expecting a particular data-type, JavaScript will automatically convert the data to that type
For example, automatic type conversion is often used for checking the existence of DOM elements. Because an Object will automatically convert to a Boolean when used in a conditional statement, this code is possible:
var element = document.getElementById("whatever");
if(element) {
//the element exists
}
else {
//the element doesn't exist
}
Question: What does NULL mean in Javascript?
The NULL value is used to represent no value or no object. A variable that is null indicates that it points to nothing. In APIs, null is often retrieved in a place where an object can be expected but no object is relevant.
Question: What is an undefined value in JavaScript?
Undefined is one of JavaScript's primitive types.
A variable that has not been assigned a value is of type undefined. A method or statement can also be undefined if it tries to use a variable that is undefined. Finally, a function returns undefined if a value was not returned.
Question: What are all the looping structures in JavaScript?
Answer:
In JavaScript we have the following looping statements:
while | loops through a block of code while a condition is true |
do...while | loops through a block of code once, and then repeats the loop while a condition is true |
for | run statements a specified number of times |
Question: What is the break statement?
The break statement exits from the current loop.
Question: What is the continue statement?
The continue statement continues with next statement of the loop.
Question: Explain how to detect the operating system on the client machine?
The navigator.appVersion string (property) can be used to detect the operating system of the client machine.
Question: What is void(0) used for?
The void operator evaluates the given expression and then returns undefined.
Void(0) is used to prevent the page from refreshing. The parameter zero is passed while calling it.
Question: What are the escape characters?
JavaScript uses the \ (backslash) as an escape characters for:
\' single quote
\" double quote
\ backslash
Next page