JavaScript __TOP__ Interview Questions

by Cosmin Potocean

About Me

  • codeartist.io
  • twitter: @cosmycx

 

web developer

General

Concept

questions

Questions are focused on JavaScript the Programming Language

JavaScript Specific

questions

Q&A is focussed on programming, not on DOM manipulation

Answers to be further discussed

What is the most efficient way to sort 100 million numbers in JavaScript?

 

or larger data set?

Things to Consider

Internal vs. External memory sorting 

  • Number double precision floating point = 64 bits​
  • distributed problem, multiple files

CPU intensive

  • JavaScript is single threaded synchronous execution, executes code sequentially
  • defer the task to external workers
  • Node.js processes & CPU Cores

Sorting Algorithms Speed? Complexity

  •  bucket sort, quick sort
  • external merge sort

You own a website with 100 pages. How do you find all the broken links using JavaScript?

 

Things to Consider

Would you start writing from scratch?

libraries available

programming approach:

  • store external links in a data structure
  • recursively look all pages for the internal links and store
  • check each link, once only

page scrapping with Node.js, using modules: request and cheerio

Design an OOP Car Park?

Application Architecture

Things to Consider

Classes & Objects

Class: a template used to create multiple Objects

Inheritance

Polymorphism

 

Automobile:

Car

Motorcycle

Car Parks:

Level 

Location

Space

 You are expected to understand all the OOP concepts.

Functional JavaScript, First Class Functions?

 

Recommended read:

Professor Frisby's Mostly Adequate Guide to Functional Programming

https://drboolean.gitbooks.io/mostly-adequate-guide/

First Class Functions?

can treat functions like any other data type ... they may be stored in variables, arrays, passed around, composed...

a function can contain:

-code

-name (optional)

-primitive types

-objects

-other functions

-arguments

Functional? computation as the evaluation of mathematical functions - avoids changing-state and mutable data.

Another recommended read: JavaScript Allonge

https://leanpub.com/javascriptallongesix/read

What is the difference between == and === ?

 

== checks value

 type conversion (coerces type)

 

=== strict equal

checks value and type

reference:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness

 

Why use ==?

coerces type

best to avoid!

Does JavaScript pass members by value or reference ?

 

Primitives by value

 

(the value of var1 gets copied to var2)

//changing var2 does not impact var 1

 

 

 

Objects by reference (copy of reference)

 

//change(mutate) of obj2 impacts obj1

 

Explain hoisting for variables & functions?

 

Functions are hoisted to top

Variables declarations are hoisted to top (not the assignment)

 

 

 

step 1: JavaScript parser reads code and set’s memory spaces 

//similar to reading an algorithm and setting aside the requirements for space (memory) 

 

step 2: then executes the program....meaning variables and functions were already declared in step 1

 

Function closures?

 

The inner function execution context closes in the outer (lexical scope) variables and can access them

 

why important?

  • create design patterns / factory pattern - a function that creates (returns) many functions /closures, module pattern.
  • create private members
  • function currying  

 

What JavaScript frameworks do you know and explain differences?

 

Why use 'use strict' ?

 

  • Can help prevent errors under some circumstances
  • JavaScript engine implements extra more stringent rules

 

 

  • may not implemented same by different JavaScript engines
  • may create issues when concatenating JavaScript files

 

OOP JavaScript?

 

prototypal inheritance

inheritance: objects gets access to another object methods

 

prototype is a reference to proto object

each object has a proto object

MAKE OBJECTS: 

1)Function Constructors

- a function that is used to construct objects

adding new changes behavior & don’t forget to add it: new!

2)Object.Create // prototypal inheritance creates objects from other objects

3)ES6 classes, class is still an object not a template!! 

3 ways to mimic OOP classes!! ...  ... stay functional!

Other Important Topics

  • namespaces
  • Object Literals
  • JSON
  • Manipulate data in/out deep nested JSON's
  • UnderscoreJS (annotated code), and Lodash
  • JS built tools
  • Promises
  • ES6
  • JQuery
  • AngularJS
  • Node.js

& most important CODE CODE CODE

TL;DR

I just want to remember one thing!

First class functions and functional programming!

Good place to start

Thank You!

JS Interview Questions

By Cosmin P

JS Interview Questions

JavaScript

  • 1,483