All Projects → tkssharma → CRACK_JS_INTERVIEWS

tkssharma / CRACK_JS_INTERVIEWS

Licence: other
CRACK JS INTERVIEW

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to CRACK JS INTERVIEWS

Grokking-the-Coding-Interview-Patterns-for-Coding-Questions
Grokking the Coding Interview: Patterns for Coding Questions Alternative
Stars: ✭ 374 (+1033.33%)
Mutual labels:  interview, interview-questions
Awesome-Software-Engineering-Interview
No description or website provided.
Stars: ✭ 409 (+1139.39%)
Mutual labels:  interview, interview-questions
Algorithmic-Problem-Solving
Solutions of algorithmic type of programming problems from sites like LeetCode.com, HackerRank.com, LeetCode.com, Codility.com, CodeForces.com, etc. using Java.
Stars: ✭ 20 (-39.39%)
Mutual labels:  interview, interview-questions
flutter interview
Flutter面试题和答案收集,各种知识点的深入研究,学完之后征服你的面试官。
Stars: ✭ 249 (+654.55%)
Mutual labels:  interview, interview-questions
counter-interview.dev
a collaborative collection of interview questions collected from both sides of the game: Interviewer(s) and Interviewee.
Stars: ✭ 102 (+209.09%)
Mutual labels:  interview, interview-questions
interview-questions
Популярные HTML / CSS / JavaScript / ECMAScript / TypeScript / React / Vue / Angular / Node вопросы на интервью и ответы на них (https://tinyurl.com/wxysrpsy)
Stars: ✭ 3,294 (+9881.82%)
Mutual labels:  interview, interview-questions
Front-end-Job-Interview-Questions
Ответы на вопросы на должность Frontend разработчика.
Stars: ✭ 236 (+615.15%)
Mutual labels:  interview, interview-questions
CsharpInterviewQuestions
A C# code collection of Interview Questions
Stars: ✭ 62 (+87.88%)
Mutual labels:  interview, interview-questions
one-note-a-day
编程每日一题:每天一道精选面试或编程题,180秒内语音答题模式凝练答案。次日推送标准参考答案至群内供大家复盘,做到事事有回音,题题有答案。
Stars: ✭ 70 (+112.12%)
Mutual labels:  interview, interview-questions
codewars python solutions
My CodeWars solutions in Python.
Stars: ✭ 111 (+236.36%)
Mutual labels:  interview, interview-questions
Test-Bank
Interview preparation and practice problems
Stars: ✭ 43 (+30.3%)
Mutual labels:  interview, interview-questions
SecurityInterviewGuide
网络信息安全从业者面试指南
Stars: ✭ 791 (+2296.97%)
Mutual labels:  interview, interview-questions
CS Offer
后台开发基础知识总结(春招/秋招)
Stars: ✭ 352 (+966.67%)
Mutual labels:  interview, interview-questions
pw
Best websites a Programmer should visit
Stars: ✭ 27 (-18.18%)
Mutual labels:  interview, interview-questions
reverse-interview-zh-tw
📖 reverse-interview 繁體中文翻譯計畫。原作者:https://github.com/viraptor/reverse-interview
Stars: ✭ 313 (+848.48%)
Mutual labels:  interview, interview-questions
Data-Structure-Algorithms-LLD-HLD
A Data Structure Algorithms Low Level Design and High Level Design collection of resources.
Stars: ✭ 922 (+2693.94%)
Mutual labels:  interview, interview-questions
front-end-interview
Front-end interview questions
Stars: ✭ 28 (-15.15%)
Mutual labels:  interview, interview-questions
CPPNotes
【C++ 面试 + C++ 学习指南】 一份涵盖大部分 C++ 程序员所需要掌握的核心知识。
Stars: ✭ 557 (+1587.88%)
Mutual labels:  interview, interview-questions
reverse-interview-zh
技术面试最后反问面试官的话
Stars: ✭ 15,141 (+45781.82%)
Mutual labels:  interview, interview-questions
reactjs-persian-interview-questions
مجموعه برترین سوال و جواب‌های ری‌اکت(احتمالا برای استخدام اینا)
Stars: ✭ 323 (+878.79%)
Mutual labels:  interview, interview-questions

Front end Interview Questions


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.

Table of Contents

Angular Interview Questions

An exclusive list of Angular interview Questions are here

JavaScript: Basics and Tricky Questions

21+ questions and answers (for intermediate)


  1. What are the differences between null and undefined?
  2. What are the differences between == and ===?
  3. How would you compare two objects in JavaScript?
  4. 11+ true false related questions that will trick you.
  5. As [] is true, [] == true should also be true. right?
  6. How could you write a method on instance of a date which will give you next day?
  7. If you want to use an arbitrary object as value of this, how will you do that?
  8. Write a simple function to tell whether 2 is passed as parameter or not?
  9. How could you use Math.max to find the max value in an array?
  10. What the heck is this in JavaScript?
  11. 21 quick questions that will trick you.
  12. How could you set a prefix before everything you log? for example, if you log('my message') it will log: "(app) my message"
  13. What will you see in the console for the following example?
  14. Look at the code below, you have a for loop if you have setTimeout inside it. If log the loop counter inside setTimeout, what will be logged?
  15. Look at the code below, I have a property in a object and I am creating a new object where I am setting it to a new value. If I delete that property what will i get if I try to access that property?
  16. Does JavaScript pass parameter by value or by reference?
  17. How could you implement cache to save calculation time for a recursive fibonacci function?
  18. How could you cache execution of any function?
  19. If you need to implement the following chaining with call back, how will you implement it?
  20. How could you implement moveLeft animation?
  21. How would you implement currying for any functions?

JS: Answer for Basics and Tricky Questions

css: Basics and Tricky Questions

21+ questions and answers


  1. What does float do?
  2. How can you clear sides of a floating element?
  3. How can you clear sides of a floating element?
  4. some tricky questions in rapid fire style
  5. Are CSS rule names case sensitive?
  6. Why css selectors mixed up with cases don't apply the styles?
  7. Does margin-top or margin-bottom has effect on inline element?
  8. Does padding-top or padding-bottom has effect on inline element?
  9. Does padding-left or padding-right or margin-left or margin-right has effect on inline element?
  10. If you have a <p> element with font-size: 10rem, will the text be responsive when the user resizes / drags the browser window?
  11. The pseudo class :checked will select inputs with type radio or checkbox, but not <option> elements.
  12. In a HTML document, the pseudo class :root always refers to the <html> element.
  13. The translate() function can move the position of an element on the z-axis.
  14. Which one would you prefer among px, em % or pt and why?
  15. How absolute, relative, fixed and static position differ?
  16. What are the differences between visibility hidden and display none?
  17. What are the differences between inline, block and inline-block?
  18. What are the properties related to box model?
  19. Does overflow: hidden create a new block formatting context?
  20. How could you apply css rules specific to a media?
  21. What is the use of only?
  22. Does the screen keyword apply to the device's physical screen or the browser's viewport?
  23. What are the some pseudo classed u have used?
  24. How do you align a p center-center inside a div?
  25. How do you optimize css selectors?
  26. How can you load css resources conditionally?
  27. Why would you use sprites?
  28. What is specificity? How do u calculate specificity?
  29. What is shadow DOM?
  30. What do you know about transition?
  31. What are the different css filter you can use?
  32. What are the reasons to use preprocessor?
  33. Show you couple of style example and you have to tell what does it do.

CSS: Answer for Basics and Tricky Questions

css Deleted questions!

Looks like these are for hardcore designer. Hence, didn't make for developers.


  1. How descendant css selectors are matched? get answer
  2. How would u implement modularity in css?
  3. If something doesn't work in a specific browser (IE8), you would u approach this problem?
  4. How do you test cross-browser compatibility of your site?
  5. What is the greatest hack you did in css so far?
  6. What is grid layout?
  7. How can you make a site responsive?
  8. Why reset css is useful? or how normalize.css works?
  9. What do you know about text shadows, box shadows?

JavaScript: Algorithm Beginners Level

20 questions and answers (for beginners)


  1. Verify a prime number?
  2. Find all prime factors of a number?
  3. Get nth Fibonacci number?
  4. Find the greatest common divisor of two numbers?
  5. Remove duplicate members from an array?
  6. merge two sorted array?
  7. Swap two numbers without using a temp variable?
  8. Reverse a string in JavaScript?
  9. How would you reverse words in a sentence?
  10. Reverse words in place?
  11. Find the first non repeating char in a string?
  12. Remove duplicate characters from a sting?
  13. How will you verify a word as palindrome?
  14. Generate random between 5 to 7 by using defined function.
  15. Find missing number from unsorted array of integers.
  16. Get two numbers that equal to a given number?
  17. Find the largest sum of any two elements?
  18. Total number of zeros from 1 upto n?
  19. Check whether a given string is a substring of bigger string
  20. Get permutations of a string

JS: Answer for Algorithm Beginners Level

JavaScript for Intermediate Level Developer

  1. What is the event loop? Can you draw a simple diagram to explain event loop?
  2. How to you explain closure?
  3. How would you make sure value of this works correctly inside setTimeout?
  4. What are the different possible values for this?
  5. What is debounce and how could you implement debounce?
  6. How would you communicate with server
  7. Explain Promise to your grandmother
  8. If and website is slow how what would you do to make it faster?
  9. What ES6 feature do you use other than let, var and arrow?
  10. What build tool you use and tell me some advantages to use that build tool

JavaScript: DOM related Questions

21+ questions and answers (for intermediate JS Developers)


  1. Is there any difference between window and document?
  2. Does document.onload and window.onload fire at the same time?
  3. Is attribute similar to property?
  4. What are the different ways to get an element from DOM?
  5. What is the fastest way to select elements by using css selectors?
  6. How come, I can't use forEach or similar array methods on a NodeList?
  7. If you need to implement getElementByAttribute, how would you implement it?
  8. How would you add a class to an element by query selector?
  9. How could I verify whether one element is child of another?
  10. What is the best way to create a DOM element? Set innherHTML or use createElement?
  11. What is createDocumentFragment and why you might use it?
  12. What is reflow? What causes reflow? How could you reduce reflow?
  13. What is repaint and when does this happen?
  14. How could you make sure to run some JavaScript when DOM is ready like $(document).ready?
  15. What is event bubble? How does event flows in DOM?
  16. How would you destroy multiple list items with one click handler?
  17. Create a button that is destroyed by clicking in it but two new buttons are created in it's place.
  18. How could you capture all clicks in a page?
  19. How can you get all the texts in a web page?
  20. What is defer and async keyword does in a script tag?
  21. 10 rapid fire questions

JS: Answers for DOM related Questions

html: Basic Questions for Begginers

15 basic questions and asnwers


  1. Why do you need doctype?
  2. What are data-* attributes used for?
  3. How can you generate a public key in html?
  4. How do you change the direction of html text?
  5. How can you highlight text in html?
  6. Can you apply css to a part of html document only?
  7. Will a browser make http request for the following cases?
  8. Which resource would be downloaded first?
  9. What is an optional tag?
  10. What are the differences between div and span?
  11. How would you differentiate between div, section, and article?
  12. How would you select svg or canvas for your site?
  13. How to serve html in multiple languages?
  14. Explain standard and quirks mode.
  15. What is a semantic tag?

HTML: Answers for Basic Questions

JavaScript: LinkedList (part 4: work in process)

Very rough stage..need to finish (for intermediate)

JavaScript: search and Sort (part 5: work in process)

Very rough stage..need to finish (for expert)

JavaScript: Binary Search Tree (part 6: work in process)

Very rough stage..need to finish (for expert)


Another Important Questions

Table of Contents

  1. What is a closure?
  2. What is the difference between apply, call, and bind?
  3. What is event delegation?
  4. What is event bubbling?
  5. What is hoisting and how does it work?
  6. What does this console?
  7. What is the prototype chain?
  8. What does this console?
  9. Rapid-fire questions!
  10. What determines the value of ‘this’?
  11. What is the event loop?
  12. What is the output?
  13. Implement curry.

1. What is a closure?

  • Access to local variables, parameters, variables in the parent scope, and global variables
  • 'Remembers' the environment in which it was created
  • Still has access to those variables even after the outer function has returned

MDN: A "closure" is an expression (typically a function) that can have free variables together with an environment that binds those variables (that "closes" the expression).

'A closure is formed when an inner function is made accessible outside of the function in which it was contained, so that it may be executed after the outer function has returned. At which point it still has access to the local variables, parameters and inner function declarations of its outer function.'

Source:

2. What is the difference between apply, call, and bind?

  • Bind allows us to set the this value on methods
    • Allows us to borrow methods
    • 'bind allows us to easily set which specific object will be bound to this when a function or method is invoked.'
    • Bind returns a function, call & apply invoke immediately
  • Apply allows us to execute a function with an array of parameters
    • each parameter is passed to the function individually
    • good for varying number of arguments
  • Call is similar to bind, but takes parameters separated by commas

Source:

3. What is event delegation?

  • Event delegation is a strategy where you attach your event handlers to a parent element rather than on multiple child elements
  • Classic example: a list (i.e. ul) with multiple li children.
  • If you want to attach some behavior for when the user clicks an li, you could either:
      1. attach an event handler to each li specifically, or
      1. attach one event listener to the parent ul and determine which child element was clicked by inspecting the event object itself when it bubbles up.

This can simplify things quite a bit, especially when li elements are going to be added and removed dynamically. It can be a hassle to manually attach and remove all those individual handlers.

Source:

4. What is event bubbling?

  • Event bubbling has to do with how events are propagated through elements in the DOM
  • When you click on an element (an li for example), that element will receive the event and then, unless you explicitly stop propagation, the event will "bubble up" to its parent element (the ul), and so on
  • After an event triggers on the deepest possible element, it then triggers on parents in nesting order.
  • The bubbling guarantees that click on Div 3 will trigger onclick first on the innermost element 3 (also caled the target), then on the element 2, and the last will be element 1.
  • The order is called a bubbling order, because an event bubbles from the innermost element up through parents, like a bubble of air in the water.
  • deepest element that triggered the element is called the event.target or event.srcElement

title

Source:

5. What is hoisting and how does it work?

MDN:

  • 'Hoisting is JavaScript's behavior of moving declarations to the top of a scope (the global scope or the current function scope).'
  • Compiler reads the entire program to find which functions/variables you have used
  • Only declarations are hoisted, not initializations

6. What does this console?

var a = 1;

function b() {
	a = 10;
	return;

	function a() {}

}
b();
console.log(a)

Answer:

1
  • within function b, the inner function a is hoisted to the top of the scope, before a is re-assigned to a value of 10.
  • because a is hoisted to the top of the scope (within b), the re-assignment of 10 does not change the global variable a.

7. What is the prototype chain?

  • Each object has an internal property called prototype, which links to another object
  • The prototype object has a prototype object of its own, and so on – this is referred to as the prototype chain
  • If you follow an object’s prototype chain, you will eventually reach the core Object prototype whose prototype is null, signalling the end of the chain.

What is the prototype chain used for?

  • When you request a property which the object does not contain, JavaScript will look down the prototype chain until it either finds the requested property, or until it reaches the end of the chain
  • This behaviour is what allows us to create “classes”, and implement inheritance.

Source:

8a What does this console?

for (var i = 0; i < 5; i++) {
  setTimeout(function() {
    console.log(i)
  }, i);
}

Answer:

Almost simultaneously,

5
5
5
5
5

i is 5 because the for loop has completed and exited by the time the callback in setTimeout is called. Since the value of i in each callback is not bound to a specific value of i, every callback returns the current value of i.

It seems simultaneous because setTimeout delay is set on 0, 1, 2, 3, and 4 ms.

8b What does this console?

for (var i = 0; i < 5; i++) {
  setTimeout(function() {
  	console.log(i)
  }, i*500);
};

Answer:

500ms apart each:

5
5
5
5
5

Similar answer as above, but the callback is now being called at 0ms, 500ms, 1s, 1.5s, and 2s.

8c How would you turn this code into its intended effect?

For example, how could you produce the output

0
1
2
3
4

with 500ms apart?

One answer:

for (var i = 0; i < 5; i++) {
  (function(i) {
    setTimeout(function() {
      console.log(i);
    }, i * 500);
  })(i);
}

Turn it into an IIFE and pass the value of i for each one.

Another answer:

for (var i = 0; i < 5; i++) {
  setTimeout(function(num) {
    console.log(num)
  }.bind(this, i), i*500);
}

Use 'bind' to bind the value of i for each callback.

9. Rapid-fire questions!

What is ...

  1. console.log(typeof []) ?
  2. console.log(typeof arguments)?
  3. console.log(typeof "hi")?
  4. console.log(typeof new String('hi'))
  5. console.log(typeof NaN)?
  6. console.log(2+true)?
  7. console.log('6'+9)?
  8. console.log(4+3+2+"1")?
  9. console.log(-'34'+10)?
  10. var a = (2, 3, 5); console.log(a)?
  11. console.log(3 instanceof Number)?
  12. console.log(typeof null)?

9. Answers

  1. console.log(typeof []) ? object. Array is derived from Object.
  2. console.log(typeof arguments)? object. arguments is an array-like object.
  3. console.log(typeof "hi")? string. This is a string primitive.
  4. console.log(typeof new String('hi')) ? object. Using new String constructor makes it an object.
  5. console.log(typeof NaN)? number. Sidenote: ES6 has a Number.isNaN function that will reliably test whether x is NaN or not, unlike the ES5 isNaN - see Flaws of ES5 isNaN. Stack Overflow explanation why NaN is a type of number.
  6. console.log(2+true)? 3. true is coerced into 1.
  7. console.log('6'+9)? 69
  8. console.log(4+3+2+"1")? 91. Evaluated from left to right.
  9. console.log(-'34'+10)? -24. -34 is coerced to -34, in the same way +34 is coerced to 34.
  10. var a = (2, 3, 5); console.log(a)? 5. The comma operator evaluates each of its operands (from left to right) and returns the value of the last operand. Detailed explanation
  11. console.log(3 instanceof Number)? false, because 3 is a primitive. console.log(new Number(4) instanceof Number) will return true.
  12. console.log(typeof null)? 'object'.

10. What determines the value of 'this'?

MDN:

  • determined by how a function is called
  • can't be set by assignment during execution

4 main patterns:

  • global reference (this usually refers to global object)
  • free function invocation (global object)
  • call/apply (first argument to call/apply)
  • method invocation (object on the left of dot, at call time)
  • construction mode (new object created for that invocation)

See HR notes on summary of binding patterns for this (since it is copyrighted material I won't put it here)

11. What is the event loop?

  • event loop runs in a single thread
  • want to avoid blocking the whole thread
  • non-blocking I/O - define a callback that is called once the action is complete
  • incoming callbacks are like events that are propagated to the event loop, which checks for new events in the queue and processes them
  • instead of waiting for the results, you can register callbacks that are executed when the event is triggered - so that you can deal with long-taking actions

I highly recommend, especially if you have difficulties understanding the event loop and questions like #8 and #14, to watch this video: What the heck is the event loop anyway?

Other:

-- Questions taken from JS By Examples --

12. What is the output?

var name = "John";

(function(){
   console.log("The name is : " + name);

   var name = "Jane";

   console.log("The name is : " +name);
})();

Answer:

The name is : undefined
The name is : Jane

Explanation in JS By Examples

13. What is the output?

var data = [0, 1, 2];
var funcs = [];

function init() { // 0
  for (var i = 0; i < 3; i++) {

    var x = data[i]; // 1
    var innerFunc = function() { // 2
      return x;
    };

    funcs.push(innerFunc); // 3
  }
}

function run() { // 4
  for (var i = 0; i < 3; i++) {
    console.log(data[i] + ", " + funcs[i]()); // 5
  }
}

init();
run();

Answer:

0, 2
1, 2
2, 2

Detailed solution by JS By Examples.

14. What is the output?

(function() {
  console.log(1);
  setTimeout(function() {
    console.log(2)
  }, 2000);
  setTimeout(function() {
    console.log(3)
  }, 0);
  console.log(4);
})();

Answer:

1
4
3
2

Solution by JS Examples

15. Implement curry such that:

var add = curry(function(a, b, c) {
  return a + b + c;
});

console.log(add(1)(2)(3));
console.log(add(1, 2)(3));
console.log(add(1)(2, 3));
console.log(add(1,2,3));

One possible solution

This is just my own solution. Aside: func.length specifies the number of arguments expected by the function.

var curry = function(func) {
  var totalNumArgs = func.length;

  return function curriedFunc() {
    var args = [].slice.call(arguments);
    if (args.length === totalNumArgs) {
      return func.apply(null, args);
    } else {
      return function () {
        var args2 = [].slice.call(arguments);
        return curriedFunc.apply(null, args.concat(args2));
      };
    }
  };
};
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].