Giter VIP home page Giter VIP logo

javascript-interview-questions's Introduction

Hi 👋 I'm Sudheer Jonna.

💻   About Me :

I am a Tech lead, Full Stack IT consultant, Author, Speaker & open source tech enthusiast from Singapore.

  • I’m working as a Senior IT consultant and building large scale web applications.
  • Authoring and blogging about emerging technologies.
  • Share knowledge through meetups and twitter.

🔥 My Stats :

Sudheer's most used languages Sudheer's github stats

🛠️ Languages and Tools :

Java  Spring  JavaScript  React  =VueJS  Angular  Redux   GraphQL  CSS  HTML  Docker  MySQL  NodeJS  AWS 

javascript-interview-questions's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

javascript-interview-questions's Issues

What is currying function?

Question 15.

Current code:

const multiArgFunction = (a, b, c) => a + b + c;
const curryUnaryFunction = a => b => c => a + b + c;
curryUnaryFunction (1); // returns a function: b => c =>  b => c => a + b + c
curryUnaryFunction (1) (2); // returns a function: c => a + b + c
curryUnaryFunction (1) (2) (3); // returns the number 6

Should be:

const multiArgFunction = (a, b, c) => a + b + c;
const curryUnaryFunction = a => b => c => a + b + c;
curryUnaryFunction (1); // returns a function: b => c =>  b => c => a + b + c
curryUnaryFunction (1) (2); // returns a function: c => a + b + c
curryUnaryFunction (1) (2) (3); // returns the number 6

Incorrect variable name - Q 412

function isPromise(object){
if(Promise && Promise.resolve){
return Promise.resolve(object) == object;
}else{
throw "Promise not supported in your environment"
}
}

var i = 1;
var promise = new Promise(function(resolve,reject){
resolve()
});

console.log(isPromise(i)); // false
console.log(isPromise(p)); // true correction // promise

Missing Debouncing and Throttling

Questions can be made

  • What is debouncing?
  • What is throttling?
  • Debouncing vs throttling
  • How to code debouncing and throttling

Many more can be formed

312:What are tagged templates

The sample code has errors.

var user1 = 'John';
var skill1 = 'JavaScript';
var experience1 = 15;

var user2 = 'Kane';
var skill2 = 'JavaScript';
var experience2 = 5;

function myInfoTag(strings, userExp, experienceExp, skillExp) {
var str0 = strings[0]; // "Mr/Ms. "
var str1 = strings[1]; // " is a/an "
var str2 = strings[2]; // "in"

var expertiseStr;
if (experienceExp > 10){
expertiseStr = 'expert developer';
} else if(skillExp > 5 && skillExp <= 10) {
expertiseStr = 'senior developer';
} else {
expertiseStr = 'junior developer';
}

return ${str0}${userExp}${str1}${experienceExp}{str3};
}

Should be:
function myInfoTag(strings, userExp, experienceExp, skillExp) {
var str0 = strings[0]; // "Mr/Ms. "
var str1 = strings[1]; // " is a/an "
var str2 = strings[2]; // "in"

var expertiseStr;
if (experienceExp > 10){
expertiseStr = 'expert developer';
} else if(skillExp > 5 && skillExp <= 10) {
expertiseStr = 'senior developer';
} else {
expertiseStr = 'junior developer';
}

return ${str0}${userExp}${str1}${expertiseStr}${str2}${skillExp};
}

What is the difference between Call, Apply and Bind? (Bind)

Question number three:
What is the difference between Call, Apply and Bind?

.
.
.
inviteEmployee1('Hello', 'How are you?'); // Hello John Rodson, How are you?
inviteEmployee1('Hello', 'How are you?'); // Hello Jimmy Baily, How are you?

Should be

.
.
.
inviteEmployee1('Hello', 'How are you?'); // Hello John Rodson, How are you?
inviteEmployee2('Hello', 'How are you?'); // Hello Jimmy Baily, How are you?

You are calling inviteEmployee1 twice.

Wrong example code for question no: 195

Please check example code for Object.seal(), you have explained Object.seal() question with Object.freeze() example. Below is code for Object.seal().

const object = {
    property: 'Welcome JS world'
 };
Object.seal(object);
console.log(Object.isSealed(object));  // true
object.property = "Welcome to object world";
console.log(object.property); // Welcome to object world

Super Array Of Objects

Count the occurrence of keys and convert the result into array of objects where each object belongs to one key and it's occurrence (count).

eg.

[{ language: 'JavaScript' },{ language: 'JavaScript' },{ language: 'TypeScript' },] 

SHOULD BE CONVERTED TO:-

[
{ language: 'JavaScript', count: 2 },
{ language: 'C++', count: 1 },
{ language: 'TypeScript', count: 1 }
]

Sounds good?

What is the purpose of array splice method?

Questions 6.
What is the purpose of array splice method?

Actual code

let arrayIntegersOriginal1 = [1, 2, 3, 4, 5];
let arrayIntegersOriginal2 = [1, 2, 3, 4, 5];
let arrayIntegersOriginal3 = [1, 2, 3, 4, 5];

let arrayIntegers1 = arrayIntegersOriginal1.splice(0,2); // returns [1, 2]; original array: [3, 4, 5]
let arrayIntegers2 = arrayIntegersOriginal2.splice(3); // returns [4, 5]; original array: [1, 2, 3]
let arrayIntegers3 = arrayIntegersOriginal3.splice(3, 1, "a", "b", "c"); //returns [4]; original array: [1, 2, 3, "a", "b", "c", 5]

Should be:

let arrayIntegersOriginal1 = [1, 2, 3, 4, 5];
let arrayIntegersOriginal2 = [1, 2, 3, 4, 5];
let arrayIntegersOriginal3 =  [1, 2, 3, "a", "b", "c", 5];

let arrayIntegers1 = arrayIntegersOriginal1.splice(0,2); // returns [1, 2]; original array: [3, 4, 5]
let arrayIntegers2 = arrayIntegersOriginal2.splice(3); // returns [4, 5]; original array: [1, 2, 3]
let arrayIntegers3 = arrayIntegersOriginal3.splice(3, 1, "a", "b", "c"); //returns ["a"]; original array: [1, 2, 3, "a", "b", "c", 5]

This code actually returns ["a"] and the original array needs to be updated

Proposal: Add a disclaimer for aspiring developers

Hello,

First of all, thanks for maintaining this list, I am sure it takes a lot of effort, and it has already helped many people.

I would like to suggest (and I am open for discussion) to add a disclaimer somewhere at the top that clarifies the purpose of the repository in more detail. As it is now, it can be pretty scary for aspiring developers, as it might make them think one has to know the answer to all these questions in order to pass an interview for what might probably be their first job in web development (I am speaking from my personal experience - a person I am mentoring is how I found out about this repo).

I would be happy to help and come up with/give feedback on such a text.

Let me know what you think, and thanks again for your efforts, appreciated!
Ante

Question 202

The line to create admin object should be instead of passing person object which does not exist:

const admin = Object.create(user);

Mistake in Coding Exercise #18

The exercise and the provided answer don't match. Specifically, there is a problem with the first line:

console.log([0] === false);

The answer claims that [0] is coerced to Number([0].valueOf().toString()), which is then coerced to false. However, this is untrue because the identity operator (===) doesn't perform type coercion. So the following expressions all return false

[0] === Number([0].valueOf().toString())
[0] === 0
[0] === false

I see two different ways to fix the exercise:

  • Change the accepted answer to "3: False, I'm True"
  • Change line 1 of the problem to use the equality operator (==) instead.

Is JavaScript faster than server side script

Is JavaScript faster than server side script -
Yes, JavaScript is faster than server side script. Because JavaScript is a client-side script it does require any web server’s help for its computation or calculation. So JavaScript is always faster than any server-side script like ASP, PHP, etc.

Yes, JavaScript is faster than server side script. Because JavaScript is a client-side script it does not require any web server’s help for its computation or calculation. So JavaScript is always faster than any server-side script like ASP, PHP, etc.

1.3 question

The object literal syntax is equivalent to create method when it passes null as parameter
No, now literal syntax is create object with Object [[prototype]]

Q.223 What are primitive data types

I think primitive data types are these below, not "null" but "object". Also, It is a duplicate of Q.78.

  1. string
  2. number
  3. boolean
  4. null(x) -> object(o)
  5. undefined

Q1. What are the possible ways to create javascript object?

IV. Constructor function
Create any function and apply the new operator to create object instances,

function Person(name){
   var object = {};
   object.name=name;
   object.age=21;
   return object;
}
var object = new Person("Sudheer");

since the description says it wants to create a new object instances, it should be:

function Person(name){
   this.name=name;
   this.age=21;
}
var object = new Person("Sudheer");

since the new operator already implicitly creates an empty object and returns it at the end. However, If the question simply wants a literal object, the new keyword can be dropped altogether.

function Person(name){
   var object = {};
   object.name=name;
   object.age=21;
   return object;
}
var object = Person("Sudheer");

Typo on Question 343

var array = [1, 2, 3, 4, 5, 6 ,7, 8, 9, 10];

var odd = element ==> element % 2 !== 0; // TypeError at ==>

console.log(array.some(odd)); // true (the odd element exists)

Should divide questions in sets (Easy / intermediate / expert) !!!

As we can see questions are listed but not sorted for users who are referring to these questions.
IT should be sort according to the level of respective question like an easy or expert level question, like that.
So request to add sections/divisions to separate questions with the difficulty level of respective questions.

5. What is the output of below code

The answer is incorrect i think. Please recheck.

var y = 1;
if (function f(){}) {
y += typeof f;
}
console.log(y);

Should be 1 i guess.
: 1function

JavaScript being used in Adobe Animate Show and Hide

I am stuck here. What I have is a interface Called Oil Facts which is landscape view. In the top left corner I have a clip saved as a movie which shows a cutaway of a engine running. I don't want the engine to be visible until the user clicks a button called engineRun. The movie of the engine running is called engine. The problem is when the engineRun button is clicked the engine appears and is animated but for a few seconds. I want the engine to stay visible and animated after the user clicks the button.
Any ideas what could be done here please. I am using Code snippets and did try adding a label in the first frame of the engine movie.

this.engine.visible = false;
this.engineRun.addEventListener("click", fl_ClickToShow_4.bind(this));

function fl_ClickToShow_4()
{
this.engine.visible = true;
this.gotoAndPlay(motorGo);
}

Mistake in Coding Exercise #57

console.log(true && '' && 0); returns ''. The operator returns the value of the first falsy operand encountered when evaluating from left to right, or the value of the last operand if they are all truthy.

image
image

What is a higher order function?

Question 13.
What is a higher order function?
Current code:

const increment = x => x+1;
const higherOrder = higherOrder(increment);
console.log(higherOrder(1));

Returns Error:

VM890:2 Uncaught ReferenceError: Cannot access 'higherOrder' before initialization
at :2:21

The answer may be wrong?

The answer of questions about rest parameters may be wrong in No.23 and No.35 which might be misleading.

example

Question 311

For question 311 on tagged templates, the function myInfoTag is missing a parameter.

Currently:
function myInfoTag(strings, userExp, experienceExp) {

It should be:
function myInfoTag(strings, userExp, experienceExp, skillExp) {

skillExp is referenced in the function body, but is not an parameter.

Also,
The two console.log's should have output1 and output2 as arguments.

console.log(output1);// Mr/Ms. John is a/an expert developer in JavaScript
console.log(output2);// Mr/Ms. Kane is a/an junior developer in JavaScript

11. What is the output of below code in non-strict mode

const printNumbers = (first, second, first) => {
console.log(first, second, first);
}
printNumbers(1, 2, 3);

const printNumbersArrow = (first, second, first) => {
console.log(first, second, first);
}
printNumbersArrow(1, 2, 3);

Wrong answer as arrow functions throw error with duplicate params. I think you want to put normal functions here.

What is the difference between Call, Apply and Bind?

Questions number 3.
Call

...
function invite(greeting1, greeting2) {
    console.log(greeting1 + ' ' + this.firstName + ' ' + this.lastName+ ', '+ this.greeting2);
}

invite.call(employee1, 'Hello', 'How are you?'); // Hello John Rodson
invite.call(employee2, 'Hello', 'How are you?'); // Hello Jimmy Baily

Should be:

....
function invite(greeting1, greeting2) {
    console.log(greeting1 + ' ' + this.firstName + ' ' + this.lastName+ ', '+ greeting2);
}

invite.call(employee1, 'Hello', 'How are you?'); // Hello John Rodson, How are you?
invite.call(employee2, 'Hello', 'How are you?'); // Hello Jimmy Baily, How are you?

in the console log inside of the function, you need to remove the this.greeting2 and leave it as greeting2. Same in the apply and bind

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.