Interview questions and answers in javascript

Here is the list of most frequently asked interview questions

Do we need module bundler when using ES6 modules?

why and when we need to bind the method in a class to this?

what is "use strict" mode in JS

When "use strict" directive is used at the beginning of scope, below restriction apply.
  • All variables must be declared
  • Few keywords are reserved and can not be used as variables like private, protected, public, static, package, interface etc

What is web assembly

What's first and third party cookie?

Explain URL object

URL class can be used to create url object for given url.

let url = new URL("http://localhost:3000/tutorials/javascript/bom-dom");

console.log(url)

/*
host: "localhost:3000"
hostname: "localhost"
href: "http://localhost:3000/tutorials/javascript/bom-dom"
origin: "http://localhost:3000"
protocol: "http:"
port: "3000"
pathname: "/tutorials/javascript/bom-dom"
search: ""
searchParams: URLSearchParams(0)
username: ""
password: ""
*/

Explain console object's methods

  • console.log, console.info, console.error, console.debug, console.warn
  • console.table - show data in tabular format
  • console.dir - show object with hirarchy
  • console.time(), console.timeEnd() and console.timeLog() - used to measure time
  • console.trace - print stack trace

this in JS

In NodeJS runtime, globalThis = global. In Browser runtime, globalThis = window.

JS animations vs CSS animations

Popular JS lib that can be used in browser for animation, drawing charts

what is mixins?

What is selection and range

What is mutation oberver in JS

Whats is shadow DOM?

What is iterator and generators

Explain property flags and descriptors

Explain property getters and setters

Explain Object creation patterns

  • - literal
  • - new Object()
  • - Object.create()
  • - Constructors

Important resources

  • https://caniuse.com/
  • https://kangax.github.io/compat-table/es6/
  • https://node.green/
  • https://zerotomastery.io/cheatsheets/javascript-cheatsheet-the-advanced-concepts/?utm_source=udemy&utm_medium=coursecontent
  • https://replit.com
  • https://www.ecma-international.org/technical-committees/tc39/

How to access all properties and methods of object


for(var key in localStorage) {
    console.log (localStorage[key]);
}

Explain closures

Using closures, we can hide inner details of function and also create public and private methods A pattern often used in place of an object with a single method, is to take advantage of closure by creating a function that returns an inner function. That inner function will have access to any variables defined in the outer function, without ever exposing those variables to a larger scope. all public methods should be returned in outer function and private methods should not be returned. public methods will access private variables and methods using closure concept.

Explain Prototypes


//prototypes

var parent = { property: 2 };

//here child object is created using parent's prototype so child will inherit properties of parent
var child = Object.create(parent);  
console.log(child.property);  

child.property = 3;
console.log(child.property);  

delete child.property;
console.log(child.property);  

difference between == and ===

=== check the equality of value and type. e.g "2"==2 is true but "2"===2 is false.

output of 1+2+"3" and "1"+2+3

1+2+"3" and "1"+2+3 will have different output - 33 and 123 respectively.

undefined vs null

All unassigned variables will have a default value of undefined. null is a object. We can delete the object reference by setting variable to null.

delete element in array


//delete an element in array

function removeAllElements(array, elem) {
    var index = array.indexOf(elem);
    while (index > -1) {
        array.splice(index, 1);
        index = array.indexOf(elem);
    }
}

How to get browser and OS details


Navigator.appVersion and Navigator.platform

How to format the Date


new Date().getDate(), getMonth(), getFullYear()

How to write multi line code

We can write multi line code by using \

void(0)

void(0) means do nothing. Even default action is not done. e.g. clicking on link will not open the new page.

Difference between call, apply and bind

Explain event bubbling

unescape() and escape() vs decodeURI() and encodeURI()

How to delete the object's property

delete keyword is used to delete the property and value.

//delete an element in array

let car= {price:20, model:"Honda"};
delete car.price;

Difference between Set and Map and WeakSet and WeakMap

Best Practises

Real life examples and challenges



Web development and Automation testing

solutions delivered!!