Front End Interview Questions

Published 2016-08-14

To rock the interview to achieve what you deserve and to improve your concepts about front end technologies, I have consolidated a list of questions and answers. It’s a one stop solution for front end interview process.

Web Core

JavaScript: basics

Types

What are the differences between undeclared, undefined, and null?

What are the differences between == and ===? To what type == operands will be converted to if they have different types?

As [] is true, [] == true should also be true, right? Explain comparison algorithm.

Why typeof {} === 'object' isn’t right? How can this pitfall be avoided?

What is NaN? What is its type? How can you reliably test if a value is equal to NaN?

What is the significance, and what are the benefits, of including 'use strict' at the beginning of a JavaScript source file?

Scope and hoisting, closure and functions

Example. What is the result will be an error?

Example. What is the result? What if to remove var value = false?

Example. What is the result?

What is a closure? What is a practical use for a closure? Provide an example.

Example. What is the result? How to make them independent?

Closures Inside in loop with setTimeout.

Write a simple function to tell whether 'foo' is passed as parameter or not?

How could you use “Math.max” to find the max value in an array?

How could you set a prefix before everything you log? for example, if you log('my message') it will log: (app) my message

Cashing / Memoization. How could you implement cache to save calculation time for a recursive fibonacci function?

Why wrapping the entire content of a JavaScript source file in IIFE?

Explain why the following doesn’t work as an IIFE: function foo(){ }();

Objects

What the heck is this in JavaScript?

Why we need call or apply or bind. If you want to use an arbitrary object as value of this, how will you do that?

How would you compare two objects?

In what order are logging properties in the object?

Why using for...in for Array iteration is wrong?

What’s the difference between for..in and for..of?

OOP

How prototype inheritance works? Are you aware of classical approach and with OOLO.

Example. Create inheritance and/or composition. When properties is not reached in child, it should be available through parent

Extend Core Object through prototype. How could you write a method on instance of a date which will give you next day?

Example. Make a subclass from parent class Animal

Rewrite previous example to ES6 classes.

Extend Core Object through prototype. Example 2. How could you make this work [1,2,3,4,5].duplicator() to return [1,2,3,4,5,1,2,3,4,5]?

Difference between: function Person(){}, var person = Person(), and var person = new Person()? What new operator do?

new F vs Object.create

DOM

Is there are a difference window VS document?

How could you make sure to run some javaScript when DOM is ready like $(document).ready?

window.onload VS document.onload VS document.addEventListener('DOMContentLoaded'). Do they fire at the same time?

Is attribute similar to property?

What are the different ways to get an element from DOM?

Fastest way to Query DOM:

Why querySelectorAll('.my-class') is slower than getElementsByClassName('my-class')?

Why we can’t use forEach or similar array methods on a NodeList? How could you solve this problem?

How would you add/remove/toggle a class to an element?

How to check if element isn’t empty, without children?

How you would perform next operation: create element with content, add data-foo attribute, append newly created element to whatever you want, then move it before some element, change text of it, remove it from DOM. How to clone an element?

How to delete all children of element?

createTextNode vs innerHTML

What is the best way to create a DOM element? Set innherHTML or use createElement? Do you know about insertAdjacentHTML?

What is createDocumentFragment and why you might use it?

When would you use “document.write()” ?

What is reflow? What causes reflow? How could you reduce reflow?

What is repaint and when does this happen?

What is defer and async attribute does in a script tag?

Events

What is event bubble? How does event flows (event phases)?

Explain event delegation

Can you remove an event handler from an element?

How could you prevent a click on an anchor from going to the link? How could you stop further propagation of an event?

How to capture all click in a page?

AJAX

Explain AJAX in as much detail as possible

What is COMET? How to achieve this technique?

How to work with HTTP headers in AJAX. Do we have a restriction?

Send JSON Object with Ajax?

Sending POST data using an XMLHttpRequest using different encoding patterns.

What is CORS? What techniques you know to avoid it?

ES6

When standard was finalized?

Tooling

Assignment Destructing, the Rapid Table

Spread Operator and Rest Parameters

Arrow Functions

Template Literals

Object Literals

Classes

Let and Const

Symbols

Iterators

Generators

Promises

Maps / WeakMaps

Sets / WeakSets

Modules

Proxy

TODO with https://ponyfoo.com/articles/es6

JavaScript: advance

What do you think of AMD vs CommonJS and ES6 modules?

What is asynchronous programming, and why is it important in JS? Non-blocking I/O in JS.

Do request two parallel request to http://httpbin.org/ip and http://httpbin.org/user-agent.

Resolve promises one after another (i.e. in sequence)?

The Event Loop

Macrotasks and Microtasks

What is the difference between “classical inheritance” and “prototypal inheritance”?

What are the pros and cons of functional programming vs object-oriented programming?

What does “favor object composition over class inheritance” mean?

What are two-way data binding and one-way data flow, and how are they different?

What are the pros and cons of monolithic vs microservice architectures?

Markup

HTML

What is doctype? Why do u need it?

Difference between standard/strict mode and quirks mode?

What is the use of data- attribute?

What is the difference between span and div?

When should you use section, div or article?

What is “Semantic HTML?”

What are some new HTML5 markup elements?

What are the new media-related elements in HTML5?

What is the difference between SVG and Canvas?

Describe the difference between cookies, sessionStorage, and localStorage

CSS

General Website Optimization Questions

How do you optimize a website’s assets?

What are ways to reduce page load time?

What kind of things must you be wary of when design or developing for multilingual sites?

Technologies

JS Framework

AngularJS

List at least three ways to communicate between modules of your application using core AngularJS functionality.

Which means of communication between modules of your application are easily testable?

The most popular e2e testing tool for AngularJS is Protractor. Describe how e2e testing of AngularJS

What are the basic steps to unit test an AngularJS filter?

When a scope is terminated, “destroy” events are fired. What are they used for, and why are there two?

How do you reset a $timeout, and disable a $watch()?

Name and describe the phases of a directive definition function execution, or describe how directives are instantiated.

How does interpolation, e.g. {% raw %}{{ someModel }}{% endraw %}, actually works?

How does the digest phase work?

List a few ways to improve performance in an AngularJS app

What is $rootScope and how does it relate to $scope?

What is the difference between “ng-show”/“ng-hide” and “ng-if” directives?

Where should we implement the DOM manipulation in AngularJS?

Is it a good or bad practice to use AngularJS together with jQuery?

If you were to migrate from Angular 1.4 to Angular 1.5, what is the main thing that would need refactoring?

Lifecycle hooks in Angular 1.5

How would you specify that a scope variable should have one-time binding only?

What is the difference between one-way binding and two-way binding?

What is the role of services in AngularJS and name any services made available by default?

What are Providers and when to use them?

Angular

What are the possible ways to bind component properties to an associated template?

Property binding or interpolation, what is better?

How you detect Detect Component Input Changes?

Angular change detection may still not fire under some circumstances. Why?

Why we need NgModules?

What kind of classes can you import (meta) in an angular module?

NgModule and scopes / visibility ?

What are template reference variables and how are they different from variables in classes?

How do you define optional fields in a TypeScript class?

What’s the difference between a TypeScript class and an interface?

What’s the difference between a promise and Observable?

How do you use a TypeScript and JavaScript (Non TypeScript) third party lib in an Angular 2 App?

Why are components not marked with @injectable annotation, but services need to be?

Lifecycle Hooks, when and why?

Parent child communication. Component interaction.

What is the proper use of an EventEmitter? How does the event emitter work in Angular 2?

How to make sure that single instance will be used in an entire application?

Why do we need to use another class with useClass or aliased providers with useExisting? When to use useValue? When to use useFactory?

What is the trackBy with *ngFor directive?

How to get dom element?

Manipulating DOM element. What is Renderer2?

How do you reference the host of a component? Have you used @HostBinding and @HostListener in custom directive?

What types of pipes are supported in Angular 2?

I18n?

How hadnle not found page / 404 ?

Why do we need an http interceptor? How to implement?

How to create a Custom Validator for Reactive Form?

How to create a Custom Validator for Template-Driven Form?

How to create a Custom Async Validator?

Fundamentals

Data Structure and algorithm

Binary search

The fastest method to create unique items in array

The fastest method to find items in array

Big-O Complexity Chart