From 9c46faf2155a4dd6465bffd91ed7ca57451f7c90 Mon Sep 17 00:00:00 2001 From: ironmaniiith Date: Fri, 11 Nov 2016 09:04:40 +0530 Subject: [PATCH 01/29] Minor typos fix --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fd68472..d5f08f3 100644 --- a/README.md +++ b/README.md @@ -86,13 +86,13 @@ var Employee = function (name, company, salary) { this.salary = salary || 5000; //Public attribute default value is null // Private method - var increaseSlary = function () { + var increaseSalary = function () { this.salary = this.salary + 1000; }; // Public method this.dispalyIncreasedSalary = function() { - increaseSlary(); + increaseSalary(); console.log(this.salary); }; }; From 24ef14bac5a6f354abd0ada57a13a73a84643ac8 Mon Sep 17 00:00:00 2001 From: ironmaniiith Date: Fri, 11 Nov 2016 17:02:47 +0530 Subject: [PATCH 02/29] Corrected minor mistake in section 4 removing the actual code out of comments --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fd68472..7512c15 100644 --- a/README.md +++ b/README.md @@ -137,8 +137,10 @@ var globalVar = "abc"; "innerArg = " + innerArg + "\n" + "innerFuncVar = " + innerFuncVar + "\n" + "globalVar = " + globalVar); - } // end of scope innerFunction)(5); // Pass 5 as parameter -} // end of scope outerFunction )(7); // Pass 7 as parameter + // end of scope innerFunction + })(5); // Pass 5 as parameter +// end of scope outerFunction +})(7); // Pass 7 as parameter ``` `innerFunction` is closure which is defined inside `outerFunction` and has access to all variable which is declared and defined in outerFunction scope. In addition to this function defined inside function as closure has access to variable which is declared in `global namespace`. From 136a33ae687eef6a1086aaeccac850003588e7f4 Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Fri, 5 May 2017 10:17:42 +0530 Subject: [PATCH 03/29] Update Nishant_resume.js --- Nishant_resume.js | 96 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 77 insertions(+), 19 deletions(-) diff --git a/Nishant_resume.js b/Nishant_resume.js index 50d65cc..113a5e5 100644 --- a/Nishant_resume.js +++ b/Nishant_resume.js @@ -1,8 +1,17 @@ /** * The Curriculum vitae of Nishant Kumar * - * Hi there, I am Nishant. I am UI Engineering Lead, JavaScript Engineer, - * Mozila Tech Contributor, CodeMentor Front-end Expert, Writer from India. + * Hi there, I am Nishant. I am Software Architect @GetMyParking, + * Mozila Tech Contributor, Teacher at CodeInstitute (Dublin), CodeMentor Front-end Expert, + * JavaScript Interview Question Author from India. + * + * I love to pair program and ship quality code that's solidly tested. + * Skills that I'm proficient in and continue to learn with: Object Oriented JavaScript, + * JavaScript Design Pattern, MVC, Client Side Performance Optimization, Node.js, Angular.js, + * Backbone.js, Vue.js, HTML5 and Tools: Git jasmine Test Framework, Grunt, webpack, bower, yoman. + * + * Domain: Cloud Computing, Distributed Systems, Big Data, SOA, Data mining, Hadoop, NoSQL and Graph Database. + * */ (function() { @@ -11,29 +20,76 @@ /* About Me */ - var me = { + const me = { name: 'Nishant Kumar', - job: 'UI Engineering Lead', - organization: 'Big Parser', - status: 'Not availble for Hire full time', - location: 'India', - experience: '5 years', + job: 'Software Architect', + organization: 'GetMyParking', + status: 'Not availble for hire', + location: 'Noida, India', + experience: '5+ years', skills: { - 'scripting-language' :['javascript'] - 'frameworks': ['angular.js','backbone.js','sails.js'], + 'scripting-language' :['JavaScript','ECMAScript 6'] + 'frameworks': ['angular.js','React','Vue','Vuex','backbone.js','IONIC','sails.js'], 'library' : ['jQuery'] - 'tools': ['Gulp', 'Grunt', 'bower','yoman','Git'], - 'testing': ['jasmine', 'protractor'], - 'backend': ['node.js', 'express.js'], + 'tools': ['Webpack','Gulp', 'Grunt', 'bower','yoman','Git'], + 'testing': ['Jasmine', 'Protractor'], + 'backend': ['Node.js', 'Express.js','Python'], 'dataBase': ['mongoDb', 'SQL'], 'uncategorized' : ['C','C#','HTML','CSS', 'HTML5','JSON'] - } + }, + work_experience:[{ + 'company' : 'GetMyParking', + 'position': 'Software Architect', + 'duration': 'Jan 2017 - April 2017', + 'location': 'New Delhi', + 'job_type': 'Contract', + 'responsibility': { + "1": 'Responsible for designing and implementing development infrastructure', + "2": 'Manage risk identification and risk mitigation strategies associated with the architecture', + "3": 'Plan for new technology insertion', + "4": 'Make sure the right modeling is being done, to know that qualities like performance are going to be met', + "5": 'Commitment to following dev "best practices", with code-reviews, unit tests, etc.', + "6": 'Migrating monolithic base code to microservice based architecture to support million transaction per day', + "7": 'Creating and ensuring best practices properly followed for Node JS, and React JS based app.' + },{ + 'company' : 'Engineering Lead', + 'position' : 'BigParser.com', + 'duration' : 'Aug 2014 - Dec 2016', + 'location' : 'Pilani, New Delhi', + 'job_type': 'Contract, Hourly,Remotely', + 'responsibility': { + "1": 'Understanding Product Feature and Functionality Requirements of the Platform', + "2": 'Working with the Design and Architecture teams on design and framework issues.', + "3": 'Working interactions on all platforms including mobile devices', + "4": 'Developing client side MVC frameworks and Creating UI Libraries and using Angular/React JS', + "5": 'Optimize Performance through improved design', + "6": 'Working with the Back End teams on Server side integration of the Platform.', + "7": 'Providing Level 2 and Level 3, support of the UI and Partner Products in Testing, Stage and Client facing Production Environments.', + "8": 'Vertical Specific Customization of Cloud Platform including interfaces to Gmail, Dropbox, Box.Net' + },{ + 'company' : 'Sr. Software Engineering', + 'position' : 'Mindfire Solutions', + 'duration' : 'June 2011 - July 2014', + 'location' : 'Bhubaneswar, New Delhi', + 'job_type': 'Full Time', + 'responsibility': { + "1": 'Analyzed the business requirement with the project manager for different clients', + "2": 'Developed the Technical and functional specifications.', + "3": 'Developed the web based solutions and windows based solutions for various clients.', + "4": 'Perform monthly performance review of the application ', + "5": 'Developed a custom GUI for the ease of users', + "6": 'Developed discussion forum for internal use of knowledge flow within the organization.', + "7": 'Providing Level 2 and Level 3, support of the UI and Partner Products in Testing, Stage and Client facing Production Environments.', + "8": 'Trained the intern coming from various collages' + } + }], + 'notes': 'For project details & more work exp details please refer my linkedIn profile.' }; /* Contact Details */ - var me_contact = { + const me_contact = { 'email' : 'nihantanu@gmail.com', 'skypeId' : 'mfsi_nishantk', 'linkedIn' :'http://in.linkedin.com/in/nishantkumar1' @@ -45,18 +101,20 @@ /* Education */ - var education = { + const education = { 'post-Graduate': { 'college': 'Birla Institute of Technology and Science, Pilani', 'Major' : 'Software System', - 'Year' :'2016' + 'Year' :'2014-2016', + 'type': 'Regular, Pilani Campus' }, 'graduation' : { 'college': 'ICFAI University, Dehradun', 'Major' : 'Computer Science & Engineering', - 'Year' :'2011' + 'Year' :'2007-2011', + 'type': 'Regular' } - } + }, /** * Nice things people have said about me. From 2320debe9cf3cd431c67d0987fd551144842f8a0 Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Fri, 5 May 2017 10:19:20 +0530 Subject: [PATCH 04/29] Update Nishant_resume.js --- Nishant_resume.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Nishant_resume.js b/Nishant_resume.js index 113a5e5..fdabaa4 100644 --- a/Nishant_resume.js +++ b/Nishant_resume.js @@ -34,7 +34,7 @@ 'tools': ['Webpack','Gulp', 'Grunt', 'bower','yoman','Git'], 'testing': ['Jasmine', 'Protractor'], 'backend': ['Node.js', 'Express.js','Python'], - 'dataBase': ['mongoDb', 'SQL'], + 'dataBase': ['mongoDb', 'MYSQL'], 'uncategorized' : ['C','C#','HTML','CSS', 'HTML5','JSON'] }, work_experience:[{ From cf255598316d4f7b18b5ee66f6877e71a40241fd Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Mon, 15 May 2017 22:39:33 +0530 Subject: [PATCH 05/29] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3dde5de..f750866 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![](coverPage.png) -## This Book will be completed by June 1 2016 and available to buy. If you want me to sent early copy of this book then please add your name and email address in google form here [Google Form](http://goo.gl/forms/QSpxVtvsNb). +## This Book will be completed by Aug 1 2017 and available to buy. If you want me to sent early copy of this book then please add your name and email address in google form here [Google Form](http://goo.gl/forms/QSpxVtvsNb). [![Join the chat at https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question](https://badges.gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question.svg)](https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) @@ -2008,7 +2008,7 @@ Answer: 1) Nishant Person ## Have doubt in this question ?? [Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) -## This Book will be completed by June 1 2016 and available to buy. If you want me to sent early copy of this book then please add your name and email address in google form here [Google Form](http://goo.gl/forms/QSpxVtvsNb). +## This Book will be completed by Aug 1 2017 and available to buy. If you want me to sent early copy of this book then please add your name and email address in google form here [Google Form](http://goo.gl/forms/QSpxVtvsNb). ##Contributing From 8f0106ef3b7aa5f1f6c421789ade8868dcb3ca30 Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Tue, 30 May 2017 21:03:58 +0530 Subject: [PATCH 06/29] Added Some more exciting questions --- README.md | 1424 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 1377 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index f750866..d2f3b18 100644 --- a/README.md +++ b/README.md @@ -1651,6 +1651,319 @@ delete employee.name; // fails silently unless it's in strict mode ``` +## Question 44 +##### Write a log function which will add prefix `(your message)` to every message you log using console.log ? +> For example, If you log `console.log("Some message")` then output should be **(your message) Some message** + +Logging error message or some informative message is always required when you dealing with client side JavaScript using console.log method. Some time you want to add some prefix to identify message generated log from your application hence you would like to prefix your app name in every console.log. + +A general way to do this keep adding your app name in every console.log message like + +```javascript +console.log('your app name' + 'some error message'); +``` +But doing in this way you have to write your app name everytime when you log message using console. + +There are some best way we can achieve this + +```javascript +function appLog() { + var args = Array.prototype.slice.call(argument); + args.unshift('your app name'); + console.log.apply(console, args); +} + +console.log(appLog("Some error message")); +//output of above console: 'your app name Some error message' +``` + +## Question 45 +##### Write a function which will test string as a literal and as an object ? + +For example: We can create string using string literal and using String constructor function. + +```javascript + // using string literal + var ltrlStr = "Hi I am string literal"; + // using String constructor function + var objStr = new String("Hi I am string object"); +``` +> We can use typeof operator to test string literal and instanceof operator to test String object. + +```javascript + function isString(str) { + return typeof(str) == 'string' || str instanceof String; + } + + var ltrlStr = "Hi I am string literal"; + var objStr = new String("Hi I am string object"); + console.log(isString(ltrlStr)); // true + console.log(isString(objStr)); // true +``` +## Question 46 +##### What is typical use case for anonymous function in JavaScript ? + +> Anonymous functions basically used in following scenario. + +1. No name is needed if function is only used in one place, then there is no need to add a name to function. + + Let's take the example of setTimeout function + + ```javascript + setTimeout(function(){ + alert("Hello"); + },1000); + ``` + Here there is no need of using named function when we are sure that function which will alert `hello` would use only once in application. + +2. Anonymous functions are declared inline and inline functions have advantages in the case that they can access variable in the parent scopes. + + Let's take a example of event handler. Notify event of particular type (such as click) for a given object. + + Let say we have HTML element (button) on which we want to add click event and when user do click on button we would like to execute some logic. + + ```html + + ``` + Add Event Listener + + ```javascript + var btn = document.getElementById('myBtn'); + btn.addEventListener('click', function () { + alert('button clicked'); + }); + ``` + + Above example shows used of anonymous function as a callback function in event handler. + +3. Passing anonymous function as a parameter to calling function. + + Example: + + ```javascript + // Function which will execute callback function + function processCallback(callback){ + if(typeof callback === 'function'){ + callback(); + } + } + + // Call function and pass anonymous function as callback + processCallback(function(){ + alert("Hi I am anonymous callback function"); + }); + ``` +The best way to take decision for using anonymous function is to asked. + +> Will the function which I am going to define will use anywhere else. + +If your answer is yes then go and create named function rather anonymous function. + +**Advantage of using anonymous function:** + +1. It can reduce a bit of code, particularly in recursive function and in callback function. +2. Avoid needless global namespace pollutions. + +## Question 47 +##### How to set a default parameter value ? + +> If you are coming from python/c# you might be using default value for function parameter incase value(formal parameter) has not been passed. For Instance : + +```python +// Define sentEmail function +// configuration : Configuration object +// provider : Email Service provider, Default would be gmail +def sentEmail(configuration, provider = 'Gmail'): + # Your code logic +``` +**In Pre ES6/ES2015** + +There are a lot of ways by which you can achieve this in pre ES2015. + +Let's understand below code by which we achieved setting default parameter value. + +**Method 1: Setting default parameter value** + +```javascript +function sentEmail(configuration, provider) { + // Set default value if user has not passed value for provider + provider = typeof provider !== 'undefined' ? provider : 'Gmail' + // Your code logic +; +} +// In this call we are not passing provider parameter value +sentEmail({ + from: 'xyz@gmail.com', + subject: 'Test Email' +}); +// Here we are passing Yahoo Mail as a provider value +sentEmail({ + from: 'xyz@gmail.com', + subject: 'Test Email' +}, 'Yahoo Mail'); +``` + +**Method 2: Setting default parameter value** + +```javascript +function sentEmail(configuration, provider) { + // Set default value if user has not passed value for provider + provider = provider || 'Gmail' + // Your code logic +; +} +// In this call we are not passing provider parameter value +sentEmail({ + from: 'xyz@gmail.com', + subject: 'Test Email' +}); +// Here we are passing Yahoo Mail as a provider value +sentEmail({ + from: 'xyz@gmail.com', + subject: 'Test Email' +}, 'Yahoo Mail'); +``` + +## Question 48 +##### Write code for merge two JavaScript Object dynamically. +> Let say you have two object + +```javascript +var person = { + name : 'John', + age : 24 +} + +var location = { + addressLine1 : 'Some Location x', + addressLine2 : 'Some Location y', + city : 'NewYork' +} +``` +Write merge function which will take two object and add all the own property of second object into first object. + +```javascript +merge(person , location); + +/* Now person should have 5 properties +name , age , addressLine1 , addressLine2 , city */ +``` +**Method 1: Using ES6, Object assign method** + +```javascript +function merge(toObj,fromObj){ + return Object.assign(person,location); +} +``` + +**Method 2: Without using in-built function** + +```javascript +function merge(toObj, fromObj) { + // Make sure both of the parameter is an object + if (typeof toObj === 'object' && typeof fromObj === 'object') { + for (var pro in fromObj) { + // Assign only own properties not inherited properties + if (fromObj.hasOwnProperty(pro)) { + // Assign property and value + toObj[pro] = fromObj[pro]; + } + } + }else{ + throw "Merge function can apply only on object"; + } +} +``` +## Question 49 +##### What is non-enumerable property in JavaScript and how can create ? + +>Object can have properties that don't show up when you iterate through object using for...in loop or using Object.keys() to get an array of property names. This properties is know as non-enumerable properties. + +Let say we have following object + +```javascript +var person = { + name: 'John' +}; +person.salary = '10000$'; +person['country'] = 'USA'; + +console.log(Object.keys(person)); // ['name', 'salary', 'country'] +``` +As we know that person object properties `name`, `salary` ,`country` are enumerable hence it's shown up when we called Object.keys(person). + +To create a non-enumerable property we have to use **Object.defineProperty()**. This is a special method for creating non-enumerable property in JavaScript. + +```javascript +var person = { + name: 'John' +}; +person.salary = '10000$'; +person['country'] = 'USA'; + +// Create non-enumerable property +Object.defineProperty(person, 'phoneNo',{ + value : '8888888888', + enumerable: false +}) + +Object.keys(person); // ['name', 'salary', 'country'] +``` +In above example `phoneNo` property didn't show up because we made it non-enumerable by setting **enumerable:false** + +Now let's try to change value of `phoneNo` + +```javascript +person.phoneNo = '7777777777'; +``` +Changing non-enumerable property value will return error in `strict mode`. In non-strict mode it won't through any error but it won't change the value of phoneNo. + +**Bonus** + +**Object.defineProperty()** is also let you create read-only properties as we saw above, we are not able to modify phoneNo value of a person object. + +## Question 50 +##### What is Function binding ? + +> Function binding falls in advance JavaScript category and this is very popular technique to use in conjunction with event handler and callback function to preserve code execution context while passing function as a parameter. + +Let's consider the following example: + +```javascript +var clickHandler = { + message: 'click event handler', + handleClick: function(event) { + console.log(this.message); + } +}; + +var btn = document.getElementById('myBtn'); +// Add click event to btn +btn.addEventListener('click', clickHandler.handleClick); +``` + +Here in this example clickHandler object is created which contain message properties and handleClick method. + +We have assigned handleClick method to a DOM button, which will be executed in response of click. When the button is clicked, then handleClick method is being called and console message. Here console.log should log the `click event handler` message but it actually log `undefined`. + +The problem of displaying `undefined` is because of the execution context of clickHandler.handleClick method is not being saved hence `this` pointing to button `btn` object. We can fix this issue using bind method. + +```javascript +var clickHandler = { + message: 'click event handler', + handleClick: function(event) { + console.log(this.message); + } +}; + +var btn = document.getElementById('myBtn'); +// Add click event to btn and bind the clickHandler object +btn.addEventListener('click', clickHandler.handleClick.bind(clickHandler)); +``` + +`bind` method is available to all the function similar to call and apply method which take argument value of `this`. + + #Objective Question ## Hoisting @@ -1695,6 +2008,154 @@ var employeeId = '1234abe'; Answer: 2) undefined +###4. What would be the output of following code? + +```javascript +var employeeId = '1234abe'; +(function() { + console.log(employeeId); + var employeeId = '122345'; + (function() { + var employeeId = 'abc1234'; + }()); +}()); +``` + +1. '122345' +2. undefined +3. '1234abe' +4. ReferenceError: employeeId is not defined + +Answer: 2) undefined + +###5. What would be the output of following code? + +```javascript +(function() { + console.log(typeof displayFunc); + var displayFunc = function(){ + console.log("Hi I am inside displayFunc"); + } +}()); +``` + +1. undefined +2. function +3. 'Hi I am inside displayFunc' +4. ReferenceError: displayFunc is not defined + +Answer: 1) undefined + +###6. What would be the output of following code? + +```javascript +var employeeId = 'abc123'; +function foo(){ + employeeId = '123bcd'; + return; +} +foo(); +console.log(employeeId); +``` + +1. undefined +2. '123bcd' +3. 'abc123' +4. ReferenceError: employeeId is not defined + +Answer: 2) '123bcd' + +###7. What would be the output of following code? + +```javascript +var employeeId = 'abc123'; + +function foo() { + employeeId = '123bcd'; + return; + + function employeeId() {} +} +foo(); +console.log(employeeId); +``` + +1. undefined +2. '123bcd' +3. 'abc123' +4. ReferenceError: employeeId is not defined + +Answer: 3) 'abc123' + +###8. What would be the output of following code? + +```javascript +var employeeId = 'abc123'; + +function foo() { + employeeId(); + return; + + function employeeId() { + console.log(typeof employeeId); + } +} +foo(); +``` + +1. undefined +2. function +3. string +4. ReferenceError: employeeId is not defined + +Answer: 2) 'function' + +###9. What would be the output of following code? + +```javascript +function foo() { + employeeId(); + var product = 'Car'; + return; + + function employeeId() { + console.log(product); + } +} +foo(); +``` + +1. undefined +2. Type Error +3. 'Car' +4. ReferenceError: product is not defined + +Answer: 1) undefined + +###10. What would be the output of following code? + +```javascript +(function foo() { + bar(); + + function bar() { + abc(); + console.log(typeof abc); + } + + function abc() { + console.log(typeof bar); + } +}()); +``` + +1. undefined undefined +2. Type Error +3. function function +4. ReferenceError: bar is not defined + +Answer: 3) function function + ## Object ###1. What would be the output of following code ? @@ -1704,7 +2165,7 @@ Answer: 2) undefined 'use strict'; var person = { - name: 'Nishant' + name: 'John' }; person.salary = '10000$'; person['country'] = 'USA'; @@ -1724,10 +2185,6 @@ Answer: 2) undefined Answer: 3) ["name", "salary", "country", "phoneNo"] -## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) - - ###2. What would be the output of following code ? ```javascript @@ -1735,7 +2192,7 @@ Answer: 3) ["name", "salary", "country", "phoneNo"] 'use strict'; var person = { - name: 'Nishant' + name: 'John' }; person.salary = '10000$'; person['country'] = 'USA'; @@ -1755,10 +2212,6 @@ Answer: 3) ["name", "salary", "country", "phoneNo"] Answer: 4) ["name", "salary", "country"] -## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) - - ###3. What would be the output of following code ? ```javascript @@ -1799,43 +2252,183 @@ Answer: 2) false false Answer: 2) false false -## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) - - -## Array - -###1. What would be the output of following code? +###5. What would be the output of following code ? ```javascript (function() { - var array = new Array('100'); - console.log(array); - console.log(array.length); + var objA = Object.create({ + foo: 'foo' + }); + var objB = Object.create({ + foo: 'foo' + }); + console.log(objA == objB); + console.log(objA === objB); }()); ``` +1. false true +2. false false +3. true false +4. true true + +Answer: 2) false false -1. undefined undefined -2. [undefined × 100] 100 -3. ["100"] 1 -4. ReferenceError: array is not defined +###6. What would be the output of following code ? -Answer: 3) ["100"] 1 +```javascript +(function() { + var objA = Object.create({ + foo: 'foo' + }); + var objB = Object.create(objA); + console.log(objA == objB); + console.log(objA === objB); +}()); +``` +1. false true +2. false false +3. true false +4. true true + +Answer: 2) false false -###2. What would be the output of following code? +###7. What would be the output of following code ? ```javascript (function() { - var array1 = []; - var array2 = new Array(100); - var array3 = new Array(['1',2,'3',4,5.6]); - console.log(array1); - console.log(array2); - console.log(array3); - console.log(array3.length); + var objA = Object.create({ + foo: 'foo' + }); + var objB = Object.create(objA); + console.log(objA.toString() == objB.toString()); + console.log(objA.toString() === objB.toString()); }()); ``` - +1. false true +2. false false +3. true false +4. true true + +Answer: 4) true true + +###8. What would be the output of following code ? + +```javascript +(function() { + var objA = Object.create({ + foo: 'foo' + }); + var objB = objA; + console.log(objA == objB); + console.log(objA === objB); + console.log(objA.toString() == objB.toString()); + console.log(objA.toString() === objB.toString()); +}()); +``` +1. true true true false +2. true false true true +3. true true true true +4. true true false false + +Answer: 3) true true true true + +###9. What would be the output of following code ? + +```javascript +(function() { + var objA = Object.create({ + foo: 'foo' + }); + var objB = objA; + objB.foo = 'bar'; + console.log(objA.foo); + console.log(objB.foo); +}()); +``` +1. foo bar +2. bar bar +3. foo foo +4. bar foo + +Answer: 2) bar bar + +###10. What would be the output of following code ? + +```javascript +(function() { + var objA = Object.create({ + foo: 'foo' + }); + var objB = objA; + objB.foo = 'bar'; + + delete objA.foo; + console.log(objA.foo); + console.log(objB.foo); +}()); +``` +1. foo bar +2. bar bar +3. foo foo +4. bar foo + +Answer: 3) foo foo + +###11. What would be the output of following code ? + +```javascript +(function() { + var objA = { + foo: 'foo' + }; + var objB = objA; + objB.foo = 'bar'; + + delete objA.foo; + console.log(objA.foo); + console.log(objB.foo); +}()); +``` +1. foo bar +2. undefined undefined +3. foo foo +4. undefined bar + +Answer: 2) undefined undefined + +## Array + +###1. What would be the output of following code? + +```javascript +(function() { + var array = new Array('100'); + console.log(array); + console.log(array.length); +}()); +``` + +1. undefined undefined +2. [undefined × 100] 100 +3. ["100"] 1 +4. ReferenceError: array is not defined + +Answer: 3) ["100"] 1 + +###2. What would be the output of following code? + +```javascript +(function() { + var array1 = []; + var array2 = new Array(100); + var array3 = new Array(['1',2,'3',4,5.6]); + console.log(array1); + console.log(array2); + console.log(array3); + console.log(array3.length); +}()); +``` + 1. [] [] [Array[5]] 1 2. [] [undefined × 100] Array[5] 5 3. [] [] ['1',2,'3',4,5.6] 5 @@ -1843,10 +2436,6 @@ Answer: 3) ["100"] 1 Answer: 1) [] [] [Array[5]] 1 -## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) - - ###3. What would be the output of following code? ```javascript @@ -1865,10 +2454,6 @@ Answer: 1) [] [] [Array[5]] 1 Answer: 1) 11 -## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) - - ###4. What would be the output of following code? ```javascript @@ -1887,6 +2472,200 @@ Answer: 1) 11 Answer: 3) 6 +###5. What would be the output of following code? + +```javascript +(function(){ + var animal = ['cow','horse']; + animal.push('cat'); + animal.unshift('dog','rat','goat'); + console.log(animal); +})(); +``` + +1. [ 'dog', 'rat', 'goat', 'cow', 'horse', 'cat' ] +2. [ 'cow', 'horse', 'cat', 'dog', 'rat', 'goat' ] +3. Type Error +4. undefined + +Answer: 1) [ 'dog', 'rat', 'goat', 'cow', 'horse', 'cat' ] + +###6. What would be the output of following code? + +```javascript +(function(){ + var array = [1,2,3,4,5]; + console.log(array.indexOf(2)); + console.log([{name: 'John'},{name : 'John'}].indexOf({name:'John'})); + console.log([[1],[2],[3],[4]].indexOf([3])); + console.log("abcdefgh".indexOf('e')); +})(); +``` + +1. 1 -1 -1 4 +2. 1 0 -1 4 +3. 1 -1 -1 -1 +4. 1 undefined -1 4 + +Answer: 1) 1 -1 -1 4 + +###7. What would be the output of following code? + +```javascript +(function(){ + var array = [1,2,3,4,5,1,2,3,4,5,6]; + console.log(array.indexOf(2)); + console.log(array.indexOf(2,3)); + console.log(array.indexOf(2,10)); +})(); +``` + +1. 1 -1 -1 +2. 1 6 -1 +3. 1 1 -1 +4. 1 undefined undefined + +Answer: 2) 1 6 -1 + +###8. What would be the output of following code? + +```javascript +(function(){ + var numbers = [2,3,4,8,9,11,13,12,16]; + var even = numbers.filter(function(element, index){ + return element % 2 === 0; + }); + console.log(even); + + var containsDivisibleby3 = numbers.some(function(element, index){ + return element % 3 === 0; + }); + + console.log(containsDivisibleby3); +})(); +``` + +1. [ 2, 4, 8, 12, 16 ] [ 0, 3, 0, 0, 9, 0, 12] +2. [ 2, 4, 8, 12, 16 ] [ 3, 9, 12] +3. [ 2, 4, 8, 12, 16 ] true +4. [ 2, 4, 8, 12, 16 ] false + +Answer: 3) [ 2, 4, 8, 12, 16 ] true + +###9. What would be the output of following code? + +```javascript +(function(){ + var containers = [2,0,false,"", '12', true]; + var containers = containers.filter(Boolean); + console.log(containers); + var containers = containers.filter(Number); + console.log(containers); + var containers = containers.filter(String); + console.log(containers); + var containers = containers.filter(Object); + console.log(containers); +})(); +``` + +1. [ 2, '12', true ] + [ 2, '12', true ] + [ 2, '12', true ] + [ 2, '12', true ] +2. [false, true] + [ 2 ] + ['12'] + [ ] +3. [2,0,false,"", '12', true] + [2,0,false,"", '12', true] + [2,0,false,"", '12', true] + [2,0,false,"", '12', true] +4. [ 2, '12', true ] + [ 2, '12', true, false ] + [ 2, '12', true,false ] + [ 2, '12', true,false] + + +Answer: 1) [ 2, '12', true ] + [ 2, '12', true ] + [ 2, '12', true ] + [ 2, '12', true ] + +###10. What would be the output of following code? + +```javascript +(function(){ + var list = ['foo','bar','john','ritz']; + console.log(list.slice(1)); + console.log(list.slice(1,3)); + console.log(list.slice()); + console.log(list.slice(2,2)); + console.log(list); +})(); +``` + +1. [ 'bar', 'john', 'ritz' ] + [ 'bar', 'john' ] + [ 'foo', 'bar', 'john', 'ritz' ] + [] + [ 'foo', 'bar', 'john', 'ritz' ] +2. [ 'bar', 'john', 'ritz' ] + [ 'bar', 'john','ritz ] + [ 'foo', 'bar', 'john', 'ritz' ] + [] + [ 'foo', 'bar', 'john', 'ritz' ] +3. [ 'john', 'ritz' ] + [ 'bar', 'john' ] + [ 'foo', 'bar', 'john', 'ritz' ] + [] + [ 'foo', 'bar', 'john', 'ritz' ] +4. [ 'foo' ] + [ 'bar', 'john' ] + [ 'foo', 'bar', 'john', 'ritz' ] + [] + [ 'foo', 'bar', 'john', 'ritz' ] + +Answer: 1) [ 'bar', 'john', 'ritz' ] + [ 'bar', 'john' ] + [ 'foo', 'bar', 'john', 'ritz' ] + [] + [ 'foo', 'bar', 'john', 'ritz' ] + +###11. What would be the output of following code? + +```javascript +(function(){ + var list = ['foo','bar','john']; + console.log(list.splice(1)); + console.log(list.splice(1,2)); + console.log(list); +})(); +``` + +1. [ 'bar', 'john' ] [] [ 'foo' ] +2. [ 'bar', 'john' ] [] [ 'bar', 'john' ] +3. [ 'bar', 'john' ] [ 'bar', 'john' ] [ 'bar', 'john' ] +4. [ 'bar', 'john' ] [] [] + +Answer: 1. [ 'bar', 'john' ] [] [ 'foo' ] + +###12. What would be the output of following code? + +```javascript +(function(){ + var arrayNumb = [2, 8, 15, 16, 23, 42]; + arrayNumb.sort(); + console.log(arrayNumb); +})(); +``` + +1. [2, 8, 15, 16, 23, 42] +2. [42, 23, 26, 15, 8, 2] +3. [ 15, 16, 2, 23, 42, 8 ] +4. [ 2, 8, 15, 16, 23, 42 ] + +Answer: 3. [ 15, 16, 2, 23, 42, 8 ] + ## Function: ###1. What would be the output of following code ? @@ -1974,6 +2753,117 @@ console.log(obj.innerMessage()); 4. ReferenceError: this.message is not defined Answer: 3) undefined + +###5. What would the output of following code ? + +```javascript +var obj = { + message: 'Hello', + innerMessage: function () { + var self = this; + (function () { + console.log(self.message); + }()); + } +}; +console.log(obj.innerMessage()); +``` + +1. Type Error +2. 'Hello' +3. undefined +4. ReferenceError: self.message is not defined + +Answer: 2) 'Hello' + +###6. What would the output of following code ? + +```javascript +function myFunc(){ + console.log(this.message); +} +myFunc.message = "Hi John"; + +console.log(myFunc()); +``` + +1. Type Error +2. 'Hi John' +3. undefined +4. ReferenceError: this.message is not defined + +Answer: 3) undefined + +###7. What would the output of following code ? + +```javascript +function myFunc(){ + console.log(myFunc.message); +} +myFunc.message = "Hi John"; + +console.log(myFunc()); +``` + +1. Type Error +2. 'Hi John' +3. undefined +4. ReferenceError: this.message is not defined + +Answer: 2) 'Hi John' + +###8. What would the output of following code ? + +```javascript +function myFunc() { + myFunc.message = 'Hi John'; + console.log(myFunc.message); +} +console.log(myFunc()); +``` + +1. Type Error +2. 'Hi John' +3. undefined +4. ReferenceError: this.message is not defined + +Answer: 2) 'Hi John' + +###9. What would the output of following code ? + +```javascript +function myFunc(param1,param2) { + console.log(myFunc.length); +} +console.log(myFunc()); +console.log(myFunc("a","b")); +console.log(myFunc("a","b","c","d")); +``` + +1. 2 2 2 +2. 0 2 4 +3. undefined +4. ReferenceError + +Answer: a) 2 2 2 + +###10. What would the output of following code ? + +```javascript +function myFunc() { + console.log(arguments.length); +} +console.log(myFunc()); +console.log(myFunc("a","b")); +console.log(myFunc("a","b","c","d")); +``` + +1. 2 2 2 +2. 0 2 4 +3. undefined +4. ReferenceError + +Answer: 2) 0 2 4 ## Object Oriented @@ -1993,17 +2883,457 @@ Person.displayName = function(){ console.log(this.name); } -var person1 = new Person('Nishant'); +var person1 = new Person('John'); person1.displayName(); Person.displayName(); ``` -1. Nishant Person -2. Nishant John -3. Nishant undefined +1. John Person +2. John John +3. John undefined 4. John John -Answer: 1) Nishant Person +Answer: 1) John Person + +## Scopes + +###1. What would the output of following code ? + +```javascript +function passWordMngr() { + var password = '12345678'; + this.userName = 'John'; + return { + pwd: password + }; +} +// Block End +var userInfo = passWordMngr(); +console.log(userInfo.pwd); +console.log(userInfo.userName); +``` + +1. 12345678 Window +2. 12345678 John +3. 12345678 undefined +4. undefined undefined + +Answer: 3) 12345678 undefined + +###2. What would the output of following code ? + +```javascript +var employeeId = 'aq123'; +function Employee() { + this.employeeId = 'bq1uy'; +} +console.log(Employee.employeeId); +``` + +1. Reference Error +2. aq123 +3. bq1uy +4. undefined + +Answer: 4) undefined + +###3. What would the output of following code ? + +```javascript +var employeeId = 'aq123'; + +function Employee() { + this.employeeId = 'bq1uy'; +} +console.log(new Employee().employeeId); +Employee.prototype.employeeId = 'kj182'; +Employee.prototype.JobId = '1BJKSJ'; +console.log(new Employee().JobId); +console.log(new Employee().employeeId); +``` + +1. bq1uy 1BJKSJ bq1uy undefined +2. bq1uy 1BJKSJ bq1uy +3. bq1uy 1BJKSJ kj182 +4. undefined 1BJKSJ kj182 + +Answer: 2) bq1uy 1BJKSJ bq1uy + +###4. What would the output of following code ? + +```javascript +var employeeId = 'aq123'; +(function Employee() { + try { + throw 'foo123'; + } catch (employeeId) { + console.log(employeeId); + } + console.log(employeeId); +}()); +``` + +1. foo123 aq123 +2. foo123 foo123 +3. aq123 aq123 +4. foo123 undefined + +Answer: 1) foo123 aq123 + +## Call, Apply, Bind + +###1. What would the output of following code ? + +```javascript +(function() { + var greet = 'Hello World'; + var toGreet = [].filter.call(greet, function(element, index) { + return index > 5; + }); + console.log(toGreet); +}()); +``` + +1. Hello World +2. undefined +3. World +4. [ 'W', 'o', 'r', 'l', 'd' ] + +Answer: 4) [ 'W', 'o', 'r', 'l', 'd' ] + +###2. What would the output of following code ? + +```javascript +(function() { + var fooAccount = { + name: 'John', + amount: 4000, + deductAmount: function(amount) { + this.amount -= amount; + return 'Total amount left in account: ' + this.amount; + } + }; + var barAccount = { + name: 'John', + amount: 6000 + }; + var withdrawAmountBy = function(totalAmount) { + return fooAccount.deductAmount.bind(barAccount, totalAmount); + }; + console.log(withdrawAmountBy(400)()); + console.log(withdrawAmountBy(300)()); +}()); +``` + +1. Total amount left in account: 5600 Total amount left in account: 5300 +2. undefined undefined +3. Total amount left in account: 3600 Total amount left in account: 3300 +4. Total amount left in account: 5600 Total amount left in account: 5600 + +Answer: 1) Total amount left in account: 5600 Total amount left in account: 5300 + +###3. What would the output of following code ? + +```javascript +(function() { + var fooAccount = { + name: 'John', + amount: 4000, + deductAmount: function(amount) { + this.amount -= amount; + return this.amount; + } + }; + var barAccount = { + name: 'John', + amount: 6000 + }; + var withdrawAmountBy = function(totalAmount) { + return fooAccount.deductAmount.apply(barAccount, [totalAmount]); + }; + console.log(withdrawAmountBy(400)); + console.log(withdrawAmountBy(300)); + console.log(withdrawAmountBy(200)); +}()); +``` + +1. 5600 5300 5100 +2. 3600 3300 3100 +3. 5600 3300 5100 +4. undefined undefined undefined + +Answer: 1) 5600 5300 5100 + +###4. What would the output of following code ? + +```javascript +(function() { + var fooAccount = { + name: 'John', + amount: 6000, + deductAmount: function(amount) { + this.amount -= amount; + return this.amount; + } + }; + var barAccount = { + name: 'John', + amount: 4000 + }; + var withdrawAmountBy = function(totalAmount) { + return fooAccount.deductAmount.call(barAccount, totalAmount); + }; + console.log(withdrawAmountBy(400)); + console.log(withdrawAmountBy(300)); + console.log(withdrawAmountBy(200)); +}()); +``` + +1. 5600 5300 5100 +2. 3600 3300 3100 +3. 5600 3300 5100 +4. undefined undefined undefined + +Answer: 2) 3600 3300 3100 + +###5. What would the output of following code ? + +```javascript +(function greetNewCustomer() { + console.log('Hello ' + this.name); +}.bind({ + name: 'John' +})()); +``` + +1. Hello John +2. Reference Error +3. Window +4. undefined + +Answer: 1) Hello John + +###6. What would the output of following code ? + +```javascript +(function greetNewCustomer() { + console.log('Hello ' + this.name); +}.bind({ + name: 'John' +})()); +``` + +1. Hello John +2. Reference Error +3. Window +4. undefined + +Answer: 1) Hello John + +## Callback Function + +###1. What would the output of following code ? + +```javascript +function getDataFromServer(apiUrl){ + var name = "John"; + return { + then : function(fn){ + fn(name); + } + } +} + +getDataFromServer('www.google.com').then(function(name){ + console.log(name); +}); + +``` + +1. John +2. undefined +3. Reference Error +4. fn is not defined + +Answer: 1) John + +###2. What would the output of following code ? + +```javascript +(function(){ + var arrayNumb = [2, 8, 15, 16, 23, 42]; + Array.prototype.sort = function(a,b){ + return a - b; + }; + arrayNumb.sort(); + console.log(arrayNumb); +})(); + +(function(){ + var numberArray = [2, 8, 15, 16, 23, 42]; + numberArray.sort(function(a,b){ + if(a == b){ + return 0; + }else{ + return a < b ? -1 : 1; + } + }); + console.log(numberArray); +})(); + +(function(){ + var numberArray = [2, 8, 15, 16, 23, 42]; + numberArray.sort(function(a,b){ + return a-b; + }); + console.log(numberArray); +})(); +``` + +1. [ 2, 8, 15, 16, 23, 42 ] + [ 2, 8, 15, 16, 23, 42 ] + [ 2, 8, 15, 16, 23, 42 ] +2. undefined undefined undefined +3. [42, 23, 16, 15, 8, 2] + [42, 23, 16, 15, 8, 2] + [42, 23, 16, 15, 8, 2] +4. Reference Error + +Answer: 1) [ 2, 8, 15, 16, 23, 42 ] + [ 2, 8, 15, 16, 23, 42 ] + [ 2, 8, 15, 16, 23, 42 ] + +## Return Statement + +###1. What would the output of following code ? + +```javascript +(function(){ + function sayHello(){ + var name = "Hi John"; + return + { + fullName: name + } + } + console.log(sayHello().fullName); +})(); +``` + +1. Hi John +2. undefined +3. Reference Error +4. Uncaught TypeError: Cannot read property 'fullName' of undefined + +Answer: 4) Uncaught TypeError: Cannot read property 'fullName' of undefined + +###2. What would the output of following code ? + +```javascript +function getNumber(){ + return (2,4,5); +} + +var numb = getNumber(); +console.log(numb); +``` + +1. 5 +2. undefined +3. 2 +4. (2,4,5) + +Answer: 1) 5 + +###3. What would the output of following code ? + +```javascript +function getNumber(){ + return; +} + +var numb = getNumber(); +console.log(numb); +``` + +1. null +2. undefined +3. "" +4. 0 + +Answer: 2) undefined + +###4**. What would the output of following code ? + +```javascript +function mul(x){ + return function(y){ + return [x*y, function(z){ + return x*y + z; + }]; + } +} + +console.log(mul(2)(3)[0]); +console.log(mul(2)(3)[1](4)); +``` + +1. 6, 10 +2. undefined undefined +3. Reference Error +4. 10, 6 + +Answer: 1) 6, 10 + +###5**. What would the output of following code ? + +```javascript +function mul(x) { + return function(y) { + return { + result: x * y, + sum: function(z) { + return x * y + z; + } + }; + }; +} +console.log(mul(2)(3).result); +console.log(mul(2)(3).sum(4)); +``` + +1. 6, 10 +2. undefined undefined +3. Reference Error +4. 10, 6 + +Answer: 1) 6, 10 + +###6. What would the output of following code ? + +```javascript +function mul(x) { + return function(y) { + return function(z) { + return function(w) { + return function(p) { + return x * y * z * w * p; + }; + }; + }; + }; +} +console.log(mul(2)(3)(4)(5)(6)); +``` + +1. 720 +2. undefined +3. Reference Error +4. Type Error + +Answer: 1) 720 + + ## Have doubt in this question ?? [Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) From 33ff3ceba14823390e6861a695a50efca794022f Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Tue, 30 May 2017 21:10:07 +0530 Subject: [PATCH 07/29] Update README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index d2f3b18..8dd9a0e 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,14 @@ [![Join the chat at https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question](https://badges.gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question.svg)](https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +##License + +This book is released under a Creative Commons Attribution-Noncommercial- No Derivative Works 3.0 United States License. + +What this means it that the project is free to read and use, but the license does not permit commercial use of the material (i.e you can freely print out the questions for your own use, but you can't sell it). I'm trying to best to publish all of my books in a free + purchased (if you would like to support these projects) form so I would greatly appreciate it if you would respect these terms. + +Copyright Nishant Kumar, 2017. + ## Have question for me ? [Ask me @nishant kumar](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) From b67812fe5ce6a12cd4a5bf2a6fae5e0978a8e6f4 Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Sat, 15 Jul 2017 15:38:25 +0530 Subject: [PATCH 08/29] Added BSD 3-Clause License --- LICENSE | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1edcd0d --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2017, Nishant Kumar +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. From 75b2d4c6570c419be0a35fb366979eae37abec42 Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Mon, 31 Jul 2017 21:40:03 +0530 Subject: [PATCH 09/29] Added Codementor Link --- README.md | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 8dd9a0e..ac5ab66 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ What this means it that the project is free to read and use, but the license doe Copyright Nishant Kumar, 2017. ## Have question for me ? -[Ask me @nishant kumar](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Ask me @nishant kumar](https://www.codementor.io/nihantanu/) # 123-JavaScript-Interview-Question ## 1. Difference between `undefined` and `not defined` in JavaScript @@ -47,7 +47,7 @@ console.log(y); // Output: ReferenceError: y is not defined [http://stackoverflow.com/questions/20822022/javascript-variable-definition-declaration](http://stackoverflow.com/questions/20822022/javascript-variable-definition-declaration) ## Have doubt in this question ?? -[Schedule time to discuss with me @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule time to discuss with me @nishantk](https://www.codementor.io/nihantanu/) ## 2. What will be the output of the following code? @@ -82,7 +82,7 @@ console.log(k); // output 1function ``` ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) ## 3. What is the drawback of creating true private in JavaScript? > One of the drawback of creating a true private method in JavaScript is that they are very memory inefficient because a new copy of the method would be created for each instance. @@ -118,7 +118,7 @@ Here each instance variable `emp1`, `emp2`, `emp3` has own copy of increaseSalar So as recommendation don't go for a private method unless it's necessary. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) ## 4.What is “closure” in javascript? Provide an example? > A closure is a function defined inside another function (called parent function) and has access to the variable which is declared and defined in parent function scope. @@ -164,7 +164,7 @@ globalVar = abc ``` ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) ## 5. Write a mul function which will properly when invoked as below syntax. @@ -265,7 +265,7 @@ while(arrayList.length) { Above implementation can also empty the array. But not recommended to use often. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) ### 7. How to check if an object is an array or not? > The best way to find whether an object is instance of a particular class or not using `toString` method from `Object.prototype` @@ -329,7 +329,7 @@ Array.isArray(arrayList); `Array.isArray` is supported by Chrome 5, Firefox 4.0, IE 9, Opera 10.5 and Safari 5 ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 8. What will be the output of the following code? @@ -345,7 +345,7 @@ console.log(output); > Above code will output `0` as output. `delete` operator is used to delete a property from an object. Here `x` is not an object it's **local variable**. `delete` operator doesn't affect local variable. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 9. What will be the output of the following code? @@ -362,7 +362,7 @@ console.log(output); > Above code will output `1` as output. `delete` operator is used to delete property from object. Here `x` is not an object it's **global variable** of type `number`. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 10. What will be the output of the following code? @@ -379,7 +379,7 @@ console.log(output); > Above code will output `undefined` as output. `delete` operator is used to delete a property from an object. Here `x` is an object which has foo as a property and from self-invoking function we are deleting foo property of object `x` and after deletion we are trying to reference deleted property `foo` which result `undefined`. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 11. What will be the output of the following code? @@ -397,7 +397,7 @@ console.log(emp1.company); `emp1` object doesn't have **company** as its own property. you can test it `console.log(emp1.hasOwnProperty('company')); //output : false` However, we can delete company property directly from `Employee` object using `delete Employee.company` or we can also delete from `emp1` object using `__proto__` property `delete emp1.__proto__.company`. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 12. What is `undefined x 1` in JavaScript @@ -411,7 +411,7 @@ when you run above code and do `console.log(trees);` in chrome developer console **Note:** Please remember you need not check for uninitialized index of array in `trees[3] === 'undefined × 1'` it will give an error, Because `'undefined × 1'` this is just way of displaying uninitialized index of array in chrome. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 13. What will be the output of the following code? @@ -426,7 +426,7 @@ console.log(trees.length); So when delete operator removes an array element that deleted element is not longer present in array. In place of value at deleted index `undefined x 1` in **chrome** and `undefined` is placed at the index. If you do `console.log(trees)` output `["xyz", "xxxx", "test", undefined × 1, "apple"]` in Chrome and in Firefox `["xyz", "xxxx", "test", undefined, "apple"]`. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 14. What will be the output of the following code? @@ -446,7 +446,7 @@ console.log(bar + false); - String + String -> Concatenation ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 15. What will be the output of the following code? @@ -458,7 +458,7 @@ console.log(y); > Above code will output `undefined` as output. According to `associativity` rule operator with the same precedence are processed based on their associativity property of operator. Here associativity of the assignment operator is `Right to Left` so first `typeof y` will evaluate first which is `undefined` and assigned to `z` and then `y` would be assigned the value of z and then `z` would be assign value `1`. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 16. What will be the output of the following code? @@ -499,7 +499,7 @@ var foo = function bar() { ``` ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 17. What is the difference between declaring a function in below format? @@ -788,7 +788,7 @@ Unlike function calls and method calls, a constructor call `new Employee('John D The primary role of the constructor function is to initialize the object. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) ## Question 23 @@ -837,7 +837,7 @@ In Javascript function defined inside has access to outer function variable and - Function can be returned from function ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) ## Question 25 @@ -892,7 +892,7 @@ methodObject.display(); Here methodObject is an object and display is a method which is associated with methodObject. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) ## Question 26 @@ -928,7 +928,7 @@ function testCallBack(callback) { testCallBack(display); // Here display function is being passed as callback ``` ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) ## Question 27 ### Describe Singleton Pattern In JavaScript? @@ -1033,7 +1033,7 @@ console.log(MyNamespace.Singleton.getInstance().publicMethod()); The singleton implemented above is easy to understand. The singleton class maintains a static reference to the lone singleton instance and return that reference from the static getInstance() method. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) ## Question 28 @@ -3344,7 +3344,7 @@ Answer: 1) 720 ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) ## This Book will be completed by Aug 1 2017 and available to buy. If you want me to sent early copy of this book then please add your name and email address in google form here [Google Form](http://goo.gl/forms/QSpxVtvsNb). @@ -3355,7 +3355,7 @@ I'm always welcome to feedback on how the book can be improved, and more questio ####Note: All contributor to this book will be added as contributor in Book Last page by default, So if you have contributed and don't wanted to be included then please write an email to me at nihantanu@gmail.com ##For any other query: -[Schedule 15 min discussion with me for free @nishantk](http://www.canumeet.com/nishantk/javascript-interview-query-discussion) +[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) ##License From a4fc9a360d99de692443fcedc05bad59864ecc7b Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Wed, 2 Aug 2017 09:25:30 +0530 Subject: [PATCH 10/29] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ac5ab66..d3f625b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![](coverPage.png) -## This Book will be completed by Aug 1 2017 and available to buy. If you want me to sent early copy of this book then please add your name and email address in google form here [Google Form](http://goo.gl/forms/QSpxVtvsNb). +## This Book will be completed by Sept 1 2017 and available to buy. If you want me to sent early copy of this book then please add your name and email address in google form here [Google Form](http://goo.gl/forms/QSpxVtvsNb). [![Join the chat at https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question](https://badges.gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question.svg)](https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) @@ -3346,7 +3346,7 @@ Answer: 1) 720 ## Have doubt in this question ?? [Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) -## This Book will be completed by Aug 1 2017 and available to buy. If you want me to sent early copy of this book then please add your name and email address in google form here [Google Form](http://goo.gl/forms/QSpxVtvsNb). +## This Book will be completed by Sep 1 2017 and available to buy. If you want me to sent early copy of this book then please add your name and email address in google form here [Google Form](http://goo.gl/forms/QSpxVtvsNb). ##Contributing From 1bce98be7af8ac88f893f63c5394bd097c2d6618 Mon Sep 17 00:00:00 2001 From: ashishyadav311 Date: Sat, 28 Oct 2017 01:02:40 +0530 Subject: [PATCH 11/29] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d3f625b..25f1c98 100644 --- a/README.md +++ b/README.md @@ -1676,7 +1676,7 @@ There are some best way we can achieve this ```javascript function appLog() { - var args = Array.prototype.slice.call(argument); + var args = Array.prototype.slice.call(arguments); args.unshift('your app name'); console.log.apply(console, args); } From 2074311804ec53829d193e248b5f97cadede35aa Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Mon, 30 Oct 2017 20:24:53 +0530 Subject: [PATCH 12/29] Update README.md --- README.md | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/README.md b/README.md index d3f625b..0226074 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,6 @@ What this means it that the project is free to read and use, but the license doe Copyright Nishant Kumar, 2017. ## Have question for me ? -[Ask me @nishant kumar](https://www.codementor.io/nihantanu/) # 123-JavaScript-Interview-Question ## 1. Difference between `undefined` and `not defined` in JavaScript @@ -47,7 +46,6 @@ console.log(y); // Output: ReferenceError: y is not defined [http://stackoverflow.com/questions/20822022/javascript-variable-definition-declaration](http://stackoverflow.com/questions/20822022/javascript-variable-definition-declaration) ## Have doubt in this question ?? -[Schedule time to discuss with me @nishantk](https://www.codementor.io/nihantanu/) ## 2. What will be the output of the following code? @@ -82,7 +80,6 @@ console.log(k); // output 1function ``` ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) ## 3. What is the drawback of creating true private in JavaScript? > One of the drawback of creating a true private method in JavaScript is that they are very memory inefficient because a new copy of the method would be created for each instance. @@ -118,7 +115,6 @@ Here each instance variable `emp1`, `emp2`, `emp3` has own copy of increaseSalar So as recommendation don't go for a private method unless it's necessary. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) ## 4.What is “closure” in javascript? Provide an example? > A closure is a function defined inside another function (called parent function) and has access to the variable which is declared and defined in parent function scope. @@ -164,7 +160,6 @@ globalVar = abc ``` ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) ## 5. Write a mul function which will properly when invoked as below syntax. @@ -265,7 +260,6 @@ while(arrayList.length) { Above implementation can also empty the array. But not recommended to use often. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) ### 7. How to check if an object is an array or not? > The best way to find whether an object is instance of a particular class or not using `toString` method from `Object.prototype` @@ -329,7 +323,6 @@ Array.isArray(arrayList); `Array.isArray` is supported by Chrome 5, Firefox 4.0, IE 9, Opera 10.5 and Safari 5 ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 8. What will be the output of the following code? @@ -345,7 +338,6 @@ console.log(output); > Above code will output `0` as output. `delete` operator is used to delete a property from an object. Here `x` is not an object it's **local variable**. `delete` operator doesn't affect local variable. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 9. What will be the output of the following code? @@ -362,7 +354,6 @@ console.log(output); > Above code will output `1` as output. `delete` operator is used to delete property from object. Here `x` is not an object it's **global variable** of type `number`. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 10. What will be the output of the following code? @@ -379,7 +370,6 @@ console.log(output); > Above code will output `undefined` as output. `delete` operator is used to delete a property from an object. Here `x` is an object which has foo as a property and from self-invoking function we are deleting foo property of object `x` and after deletion we are trying to reference deleted property `foo` which result `undefined`. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 11. What will be the output of the following code? @@ -397,7 +387,6 @@ console.log(emp1.company); `emp1` object doesn't have **company** as its own property. you can test it `console.log(emp1.hasOwnProperty('company')); //output : false` However, we can delete company property directly from `Employee` object using `delete Employee.company` or we can also delete from `emp1` object using `__proto__` property `delete emp1.__proto__.company`. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 12. What is `undefined x 1` in JavaScript @@ -411,7 +400,6 @@ when you run above code and do `console.log(trees);` in chrome developer console **Note:** Please remember you need not check for uninitialized index of array in `trees[3] === 'undefined × 1'` it will give an error, Because `'undefined × 1'` this is just way of displaying uninitialized index of array in chrome. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 13. What will be the output of the following code? @@ -426,7 +414,6 @@ console.log(trees.length); So when delete operator removes an array element that deleted element is not longer present in array. In place of value at deleted index `undefined x 1` in **chrome** and `undefined` is placed at the index. If you do `console.log(trees)` output `["xyz", "xxxx", "test", undefined × 1, "apple"]` in Chrome and in Firefox `["xyz", "xxxx", "test", undefined, "apple"]`. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 14. What will be the output of the following code? @@ -446,7 +433,6 @@ console.log(bar + false); - String + String -> Concatenation ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 15. What will be the output of the following code? @@ -458,7 +444,6 @@ console.log(y); > Above code will output `undefined` as output. According to `associativity` rule operator with the same precedence are processed based on their associativity property of operator. Here associativity of the assignment operator is `Right to Left` so first `typeof y` will evaluate first which is `undefined` and assigned to `z` and then `y` would be assigned the value of z and then `z` would be assign value `1`. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) #### 16. What will be the output of the following code? From fbc499a704cd366ad9d00e77720b107cc596c9b7 Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Mon, 30 Oct 2017 20:26:02 +0530 Subject: [PATCH 13/29] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0226074..4595f8a 100644 --- a/README.md +++ b/README.md @@ -484,7 +484,7 @@ var foo = function bar() { ``` ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) + #### 17. What is the difference between declaring a function in below format? @@ -773,7 +773,7 @@ Unlike function calls and method calls, a constructor call `new Employee('John D The primary role of the constructor function is to initialize the object. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) + ## Question 23 @@ -822,7 +822,7 @@ In Javascript function defined inside has access to outer function variable and - Function can be returned from function ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) + ## Question 25 @@ -877,7 +877,7 @@ methodObject.display(); Here methodObject is an object and display is a method which is associated with methodObject. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) + ## Question 26 @@ -913,7 +913,7 @@ function testCallBack(callback) { testCallBack(display); // Here display function is being passed as callback ``` ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) + ## Question 27 ### Describe Singleton Pattern In JavaScript? @@ -1018,7 +1018,7 @@ console.log(MyNamespace.Singleton.getInstance().publicMethod()); The singleton implemented above is easy to understand. The singleton class maintains a static reference to the lone singleton instance and return that reference from the static getInstance() method. ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) + ## Question 28 @@ -3329,7 +3329,7 @@ Answer: 1) 720 ## Have doubt in this question ?? -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) + ## This Book will be completed by Sep 1 2017 and available to buy. If you want me to sent early copy of this book then please add your name and email address in google form here [Google Form](http://goo.gl/forms/QSpxVtvsNb). @@ -3340,7 +3340,7 @@ I'm always welcome to feedback on how the book can be improved, and more questio ####Note: All contributor to this book will be added as contributor in Book Last page by default, So if you have contributed and don't wanted to be included then please write an email to me at nihantanu@gmail.com ##For any other query: -[Schedule 15 min discussion with me for free @nishantk](https://www.codementor.io/nihantanu/) + ##License From 90cef3e595bf2391a49623ff1917bc16e702ce05 Mon Sep 17 00:00:00 2001 From: Omar El Gabry Date: Sun, 19 Nov 2017 16:44:06 +0530 Subject: [PATCH 14/29] Update Length of counterArray It outputs 3 since you added `counterArray["C"] = 1;` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4595f8a..14e37c7 100644 --- a/README.md +++ b/README.md @@ -684,7 +684,7 @@ counterArray["C"] = 1; `Object` has `keys` method which can we used to calculate the length of object. ```javascript -Object.keys(counterArray).length; // Output 2 +Object.keys(counterArray).length; // Output 3 ``` We can also calculate length of object by iterating through the object and by doing a count of own property of object. From acf71f005a9ca3126d88d7d5fe8ed82a3e8e700c Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Mon, 4 Dec 2017 20:36:55 +0530 Subject: [PATCH 15/29] Deleted Nishant Resume --- Nishant_resume.js | 175 ---------------------------------------------- 1 file changed, 175 deletions(-) delete mode 100644 Nishant_resume.js diff --git a/Nishant_resume.js b/Nishant_resume.js deleted file mode 100644 index fdabaa4..0000000 --- a/Nishant_resume.js +++ /dev/null @@ -1,175 +0,0 @@ -/** - * The Curriculum vitae of Nishant Kumar - * - * Hi there, I am Nishant. I am Software Architect @GetMyParking, - * Mozila Tech Contributor, Teacher at CodeInstitute (Dublin), CodeMentor Front-end Expert, - * JavaScript Interview Question Author from India. - * - * I love to pair program and ship quality code that's solidly tested. - * Skills that I'm proficient in and continue to learn with: Object Oriented JavaScript, - * JavaScript Design Pattern, MVC, Client Side Performance Optimization, Node.js, Angular.js, - * Backbone.js, Vue.js, HTML5 and Tools: Git jasmine Test Framework, Grunt, webpack, bower, yoman. - * - * Domain: Cloud Computing, Distributed Systems, Big Data, SOA, Data mining, Hadoop, NoSQL and Graph Database. - * - */ - -(function() { - 'use strict'; - - /* - About Me - */ - const me = { - name: 'Nishant Kumar', - job: 'Software Architect', - organization: 'GetMyParking', - status: 'Not availble for hire', - location: 'Noida, India', - experience: '5+ years', - skills: { - 'scripting-language' :['JavaScript','ECMAScript 6'] - 'frameworks': ['angular.js','React','Vue','Vuex','backbone.js','IONIC','sails.js'], - 'library' : ['jQuery'] - 'tools': ['Webpack','Gulp', 'Grunt', 'bower','yoman','Git'], - 'testing': ['Jasmine', 'Protractor'], - 'backend': ['Node.js', 'Express.js','Python'], - 'dataBase': ['mongoDb', 'MYSQL'], - 'uncategorized' : ['C','C#','HTML','CSS', 'HTML5','JSON'] - }, - work_experience:[{ - 'company' : 'GetMyParking', - 'position': 'Software Architect', - 'duration': 'Jan 2017 - April 2017', - 'location': 'New Delhi', - 'job_type': 'Contract', - 'responsibility': { - "1": 'Responsible for designing and implementing development infrastructure', - "2": 'Manage risk identification and risk mitigation strategies associated with the architecture', - "3": 'Plan for new technology insertion', - "4": 'Make sure the right modeling is being done, to know that qualities like performance are going to be met', - "5": 'Commitment to following dev "best practices", with code-reviews, unit tests, etc.', - "6": 'Migrating monolithic base code to microservice based architecture to support million transaction per day', - "7": 'Creating and ensuring best practices properly followed for Node JS, and React JS based app.' - },{ - 'company' : 'Engineering Lead', - 'position' : 'BigParser.com', - 'duration' : 'Aug 2014 - Dec 2016', - 'location' : 'Pilani, New Delhi', - 'job_type': 'Contract, Hourly,Remotely', - 'responsibility': { - "1": 'Understanding Product Feature and Functionality Requirements of the Platform', - "2": 'Working with the Design and Architecture teams on design and framework issues.', - "3": 'Working interactions on all platforms including mobile devices', - "4": 'Developing client side MVC frameworks and Creating UI Libraries and using Angular/React JS', - "5": 'Optimize Performance through improved design', - "6": 'Working with the Back End teams on Server side integration of the Platform.', - "7": 'Providing Level 2 and Level 3, support of the UI and Partner Products in Testing, Stage and Client facing Production Environments.', - "8": 'Vertical Specific Customization of Cloud Platform including interfaces to Gmail, Dropbox, Box.Net' - },{ - 'company' : 'Sr. Software Engineering', - 'position' : 'Mindfire Solutions', - 'duration' : 'June 2011 - July 2014', - 'location' : 'Bhubaneswar, New Delhi', - 'job_type': 'Full Time', - 'responsibility': { - "1": 'Analyzed the business requirement with the project manager for different clients', - "2": 'Developed the Technical and functional specifications.', - "3": 'Developed the web based solutions and windows based solutions for various clients.', - "4": 'Perform monthly performance review of the application ', - "5": 'Developed a custom GUI for the ease of users', - "6": 'Developed discussion forum for internal use of knowledge flow within the organization.', - "7": 'Providing Level 2 and Level 3, support of the UI and Partner Products in Testing, Stage and Client facing Production Environments.', - "8": 'Trained the intern coming from various collages' - } - }], - 'notes': 'For project details & more work exp details please refer my linkedIn profile.' - }; - - /* - Contact Details - */ - const me_contact = { - 'email' : 'nihantanu@gmail.com', - 'skypeId' : 'mfsi_nishantk', - 'linkedIn' :'http://in.linkedin.com/in/nishantkumar1' - 'gitHub' : 'github.com/nishant8BITS' - 'stackOverFlow' : 'http://stackoverflow.com/users/430803/nishant' - 'codementor': 'codementor.io/nihantanu' - } - - /* - Education - */ - const education = { - 'post-Graduate': { - 'college': 'Birla Institute of Technology and Science, Pilani', - 'Major' : 'Software System', - 'Year' :'2014-2016', - 'type': 'Regular, Pilani Campus' - }, - 'graduation' : { - 'college': 'ICFAI University, Dehradun', - 'Major' : 'Computer Science & Engineering', - 'Year' :'2007-2011', - 'type': 'Regular' - } - }, - - /** - * Nice things people have said about me. - */ - - /** - * Nishant is a very smart and thoughtful person as an engineer. He truly cares - * about helping others and values the learning experience for young software - * engineers. He is very patient - a key trait as an engineer. Nishant will help - * guide you through problems and help you understand software engineering - * concepts. Hands down I would hire Nishant to be on a team that will not only - * help a business but help other engineers grow as well. - * -Gary Tsai, Software Engineer - */ - - /** - * Nishant is a quick learner and he has very deep understanding on UI stack. He - * also is a good mentor and help other to understand the technology stack. One - * good thing I observed while working with him is he always focus on insist on - * highest standard in his code/solution as well as idea. Keep it up. - * -Apurv Gupta (WDE II at Amazon) - */ - - /** - * Nishant is one of the best person I'm working with. Along with his strong - * technical understanding of how things work, he also keeps on motivating to team - * and helps them to participate effectively & maintaining their productivity to - * better work towards achieving a goal. He always prefers to have full stack - * knowledge of the product & leads a team with great enthusiasm. He can deliver - * end to end any product he is working on. - * -Yash Shah (SRE at Linkedin) - */ - - /** - * I have been working with Nishant since last one year on a cloud-based product, - * He is one of the vibrant contributor in the team and always been dedicated to - * his work. He has very good level of knowledge when it comes to overall front-end - * architecture solutions and specifically on frameworks like backbone & angular. - * -Mohiuddin Parekh ( Founder & CEO at Decojent) - */ - - /** - * I first met Nishant 3 months ago when I told him I was looking for help with - * AngularJS and asked him to mentor me. One of the first things I noticed was that - * he had a great learning attitude, because he told me that he was looking forward - * to learning from me, something I wasn’t expecting from a mentor! He is fun, - * sweet, generous and has a great sense of humor. We have quickly become friends - * and I think we have spent more time hanging out on Telegram (instant messaging) - * and Skype than we have coding. I had never written my own AngularJS directive - * before so I asked him if he could write one for me for an autocomplete feature. - * I was impressed with his work and because of it I was then able to write my own - * directives. We have spent a lot of time chatting and I think there is so much - * more he can do that I have not yet seen. I can see he also has a passion for - * startups. - * -Jenny Swift (Software Engineer) - */ - -})(); From 22ce378b162949dd85de9ad23abcd5bed4d75d7d Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Mon, 4 Dec 2017 20:38:44 +0530 Subject: [PATCH 16/29] Added Iurii in copyright info --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4595f8a..43c5cbb 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This book is released under a Creative Commons Attribution-Noncommercial- No Der What this means it that the project is free to read and use, but the license does not permit commercial use of the material (i.e you can freely print out the questions for your own use, but you can't sell it). I'm trying to best to publish all of my books in a free + purchased (if you would like to support these projects) form so I would greatly appreciate it if you would respect these terms. -Copyright Nishant Kumar, 2017. +Copyright Iurii Katkov and Nishant Kumar, 2017. ## Have question for me ? @@ -3349,4 +3349,4 @@ This book is released under a Creative Commons Attribution-Noncommercial- No Der What this means it that the project is free to read and use, but the license does not permit commercial use of the material (i.e you can freely print out the questions for your own use, but you can't sell it). I'm trying to best to publish all of my books in a free + purchased (if you would like to support these projects) form so I would greatly appreciate it if you would respect these terms. -Copyright Nishant Kumar, 2016. +Copyright Iurii Katkov and Nishant Kumar, 2017. From 95c64853b8ef81235b87d46858ccef6b1447edc4 Mon Sep 17 00:00:00 2001 From: Nishant Kumar Date: Mon, 4 Dec 2017 20:41:07 +0530 Subject: [PATCH 17/29] Removed Form --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 43c5cbb..520e425 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ![](coverPage.png) -## This Book will be completed by Sept 1 2017 and available to buy. If you want me to sent early copy of this book then please add your name and email address in google form here [Google Form](http://goo.gl/forms/QSpxVtvsNb). + [![Join the chat at https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question](https://badges.gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question.svg)](https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) @@ -3331,8 +3331,6 @@ Answer: 1) 720 ## Have doubt in this question ?? -## This Book will be completed by Sep 1 2017 and available to buy. If you want me to sent early copy of this book then please add your name and email address in google form here [Google Form](http://goo.gl/forms/QSpxVtvsNb). - ##Contributing I'm always welcome to feedback on how the book can be improved, and more questions can be added. If you think you have some question then please add that and open a pull request. From 5c9cb19d428c5533e0d2e20ca233d2dfffe4c0d3 Mon Sep 17 00:00:00 2001 From: Yuri Katkov Date: Thu, 7 Dec 2017 10:04:39 +0100 Subject: [PATCH 18/29] Update README.md Message about the new contributor and flashcards.js --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 520e425..788c503 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ ![](coverPage.png) - +##Great news! +Even though the book is yet to be published, you can get something physical with carefully chosen interview questions. (https://flashcardsjs.com?utm_media=github)[Flashcards.js] is a deck of learning cards that will help you to ace you job interview. Yuri Katkov will work on enriching the book with the qustions from his flashcards collection and to create an unbeatable guide to pass any interview. [![Join the chat at https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question](https://badges.gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question.svg)](https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) From 51736c65daf93ddb8d7d04d1d300ebdf13b11801 Mon Sep 17 00:00:00 2001 From: Yuri Katkov Date: Thu, 7 Dec 2017 10:08:19 +0100 Subject: [PATCH 19/29] Update README.md Typo in markup --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 788c503..979eda2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ ![](coverPage.png) ##Great news! -Even though the book is yet to be published, you can get something physical with carefully chosen interview questions. (https://flashcardsjs.com?utm_media=github)[Flashcards.js] is a deck of learning cards that will help you to ace you job interview. Yuri Katkov will work on enriching the book with the qustions from his flashcards collection and to create an unbeatable guide to pass any interview. + +Even though the book is yet to be published, you can get something physical with carefully chosen interview questions. [Flashcards.js](https://flashcardsjs.com?utm_media=github) is a deck of learning cards that will help you to ace you job interview. Yuri Katkov will work on enriching the book with the qustions from his flashcards collection and to create an unbeatable guide to pass any interview. [![Join the chat at https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question](https://badges.gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question.svg)](https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) From 63882df5c5f90958c349d67e3b5c0dbe1202466e Mon Sep 17 00:00:00 2001 From: Yuri Katkov Date: Thu, 7 Dec 2017 10:10:06 +0100 Subject: [PATCH 20/29] Update README.md Fixed link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 979eda2..86e2ea4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ##Great news! -Even though the book is yet to be published, you can get something physical with carefully chosen interview questions. [Flashcards.js](https://flashcardsjs.com?utm_media=github) is a deck of learning cards that will help you to ace you job interview. Yuri Katkov will work on enriching the book with the qustions from his flashcards collection and to create an unbeatable guide to pass any interview. +Even though the book is yet to be published, you can get something physical with carefully chosen interview questions. [Flashcards.js](https://flashcardsjs.com) is a deck of learning cards that will help you to ace you job interview. Yuri Katkov will work on enriching the book with the qustions from his flashcards collection and to create an unbeatable guide to pass any interview. [![Join the chat at https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question](https://badges.gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question.svg)](https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) From 51331518fd1b44925032aa5366bc7f4a92a39614 Mon Sep 17 00:00:00 2001 From: Yuri Katkov Date: Thu, 7 Dec 2017 10:11:37 +0100 Subject: [PATCH 21/29] Update README.md Http instead of https --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 86e2ea4..41b588c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ##Great news! -Even though the book is yet to be published, you can get something physical with carefully chosen interview questions. [Flashcards.js](https://flashcardsjs.com) is a deck of learning cards that will help you to ace you job interview. Yuri Katkov will work on enriching the book with the qustions from his flashcards collection and to create an unbeatable guide to pass any interview. +Even though the book is yet to be published, you can get something physical with carefully chosen interview questions. [Flashcards.js](http://flashcardsjs.com) is a deck of learning cards that will help you to ace you job interview. Yuri Katkov will work on enriching the book with the qustions from his flashcards collection and to create an unbeatable guide to pass any interview. [![Join the chat at https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question](https://badges.gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question.svg)](https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) From c4acd75c71961d1c4dc1f9a340b1d8ad5d6f47ac Mon Sep 17 00:00:00 2001 From: Yuri Katkov Date: Sun, 10 Dec 2017 14:36:26 +0100 Subject: [PATCH 22/29] Update README.md trying to fix the markup --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5f29fe0..53f476b 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,11 @@ ![](coverPage.png) -##Great news! +#Great news! Even though the book is yet to be published, you can get something physical with carefully chosen interview questions. [Flashcards.js](http://flashcardsjs.com) is a deck of learning cards that will help you to ace you job interview. Yuri Katkov will work on enriching the book with the qustions from his flashcards collection and to create an unbeatable guide to pass any interview. -[![Join the chat at https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question](https://badges.gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question.svg)](https://gitter.im/nishant8BITS/123-Essential-JavaScript-Interview-Question?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -##License +#License This book is released under a Creative Commons Attribution-Noncommercial- No Derivative Works 3.0 United States License. @@ -14,7 +13,6 @@ What this means it that the project is free to read and use, but the license doe Copyright Iurii Katkov and Nishant Kumar, 2017. -## Have question for me ? # 123-JavaScript-Interview-Question ## 1. Difference between `undefined` and `not defined` in JavaScript From 8f7c30dbe9baef5c3dea8b61267ea0e5e0108a05 Mon Sep 17 00:00:00 2001 From: Yuri Katkov Date: Sun, 10 Dec 2017 15:06:44 +0100 Subject: [PATCH 23/29] Update README.md fixing markdown errors --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 53f476b..4437889 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ ![](coverPage.png) -#Great news! +# 123-JavaScript-Interview-Question + +##Great news! Even though the book is yet to be published, you can get something physical with carefully chosen interview questions. [Flashcards.js](http://flashcardsjs.com) is a deck of learning cards that will help you to ace you job interview. Yuri Katkov will work on enriching the book with the qustions from his flashcards collection and to create an unbeatable guide to pass any interview. -#License +##License This book is released under a Creative Commons Attribution-Noncommercial- No Derivative Works 3.0 United States License. @@ -14,7 +16,6 @@ What this means it that the project is free to read and use, but the license doe Copyright Iurii Katkov and Nishant Kumar, 2017. -# 123-JavaScript-Interview-Question ## 1. Difference between `undefined` and `not defined` in JavaScript > In JavaScript if you try to use a variable that doesn't exist and has not been declared, then JavaScript will throw an error `var name is not defined` and the script will stop execute thereafter. But If you use `typeof undeclared_variable` then it will return `undefined`. From 2ba9e2b5c332c53cf46bd3d3c8314fc77cceef84 Mon Sep 17 00:00:00 2001 From: Yuri Katkov Date: Sun, 10 Dec 2017 15:07:27 +0100 Subject: [PATCH 24/29] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4437889..105d757 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,12 @@ # 123-JavaScript-Interview-Question -##Great news! +## Great news! Even though the book is yet to be published, you can get something physical with carefully chosen interview questions. [Flashcards.js](http://flashcardsjs.com) is a deck of learning cards that will help you to ace you job interview. Yuri Katkov will work on enriching the book with the qustions from his flashcards collection and to create an unbeatable guide to pass any interview. -##License +## License This book is released under a Creative Commons Attribution-Noncommercial- No Derivative Works 3.0 United States License. From 656f1d74566a3732b52d4c408c70c8df73ad30de Mon Sep 17 00:00:00 2001 From: Yuri Katkov Date: Sun, 10 Dec 2017 20:52:59 +0100 Subject: [PATCH 25/29] Update README.md --- README.md | 48 +++++++++++++----------------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 105d757..f986eac 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,10 @@ ![](coverPage.png) -# 123-JavaScript-Interview-Question +# 123-JavaScript-Interview-Questions ## Great news! -Even though the book is yet to be published, you can get something physical with carefully chosen interview questions. [Flashcards.js](http://flashcardsjs.com) is a deck of learning cards that will help you to ace you job interview. Yuri Katkov will work on enriching the book with the qustions from his flashcards collection and to create an unbeatable guide to pass any interview. - - -## License - -This book is released under a Creative Commons Attribution-Noncommercial- No Derivative Works 3.0 United States License. - -What this means it that the project is free to read and use, but the license does not permit commercial use of the material (i.e you can freely print out the questions for your own use, but you can't sell it). I'm trying to best to publish all of my books in a free + purchased (if you would like to support these projects) form so I would greatly appreciate it if you would respect these terms. - -Copyright Iurii Katkov and Nishant Kumar, 2017. - +Yuri Katkov from [Flashcards.js](http://flashcardsjs.com) became a co-author and the rights holder of the book. He will improve the questions and add some more from his collections of flashcards and will make sure to produce an unbeatable guide for frontend inteviews. ## 1. Difference between `undefined` and `not defined` in JavaScript > In JavaScript if you try to use a variable that doesn't exist and has not been declared, then JavaScript will throw an error `var name is not defined` and the script will stop execute thereafter. But If you use `typeof undeclared_variable` then it will return `undefined`. @@ -46,7 +36,6 @@ console.log(y); // Output: ReferenceError: y is not defined ### Ref Link: [http://stackoverflow.com/questions/20822022/javascript-variable-definition-declaration](http://stackoverflow.com/questions/20822022/javascript-variable-definition-declaration) -## Have doubt in this question ?? ## 2. What will be the output of the following code? @@ -80,7 +69,6 @@ if (1) { console.log(k); // output 1function ``` -## Have doubt in this question ?? ## 3. What is the drawback of creating true private in JavaScript? > One of the drawback of creating a true private method in JavaScript is that they are very memory inefficient because a new copy of the method would be created for each instance. @@ -115,8 +103,6 @@ Here each instance variable `emp1`, `emp2`, `emp3` has own copy of increaseSalar So as recommendation don't go for a private method unless it's necessary. -## Have doubt in this question ?? - ## 4.What is “closure” in javascript? Provide an example? > A closure is a function defined inside another function (called parent function) and has access to the variable which is declared and defined in parent function scope. @@ -160,8 +146,6 @@ innerFuncVar = y globalVar = abc ``` -## Have doubt in this question ?? - ## 5. Write a mul function which will properly when invoked as below syntax. ```javascript @@ -260,7 +244,6 @@ while(arrayList.length) { Above implementation can also empty the array. But not recommended to use often. -## Have doubt in this question ?? ### 7. How to check if an object is an array or not? > The best way to find whether an object is instance of a particular class or not using `toString` method from `Object.prototype` @@ -323,7 +306,6 @@ Array.isArray(arrayList); `Array.isArray` is supported by Chrome 5, Firefox 4.0, IE 9, Opera 10.5 and Safari 5 -## Have doubt in this question ?? #### 8. What will be the output of the following code? @@ -338,7 +320,6 @@ console.log(output); > Above code will output `0` as output. `delete` operator is used to delete a property from an object. Here `x` is not an object it's **local variable**. `delete` operator doesn't affect local variable. -## Have doubt in this question ?? #### 9. What will be the output of the following code? @@ -354,7 +335,6 @@ console.log(output); > Above code will output `1` as output. `delete` operator is used to delete property from object. Here `x` is not an object it's **global variable** of type `number`. -## Have doubt in this question ?? #### 10. What will be the output of the following code? @@ -370,7 +350,6 @@ console.log(output); > Above code will output `undefined` as output. `delete` operator is used to delete a property from an object. Here `x` is an object which has foo as a property and from self-invoking function we are deleting foo property of object `x` and after deletion we are trying to reference deleted property `foo` which result `undefined`. -## Have doubt in this question ?? #### 11. What will be the output of the following code? @@ -387,7 +366,6 @@ console.log(emp1.company); `emp1` object doesn't have **company** as its own property. you can test it `console.log(emp1.hasOwnProperty('company')); //output : false` However, we can delete company property directly from `Employee` object using `delete Employee.company` or we can also delete from `emp1` object using `__proto__` property `delete emp1.__proto__.company`. -## Have doubt in this question ?? #### 12. What is `undefined x 1` in JavaScript @@ -400,7 +378,7 @@ when you run above code and do `console.log(trees);` in chrome developer console **Note:** Please remember you need not check for uninitialized index of array in `trees[3] === 'undefined × 1'` it will give an error, Because `'undefined × 1'` this is just way of displaying uninitialized index of array in chrome. -## Have doubt in this question ?? + #### 13. What will be the output of the following code? @@ -414,7 +392,7 @@ console.log(trees.length); So when delete operator removes an array element that deleted element is not longer present in array. In place of value at deleted index `undefined x 1` in **chrome** and `undefined` is placed at the index. If you do `console.log(trees)` output `["xyz", "xxxx", "test", undefined × 1, "apple"]` in Chrome and in Firefox `["xyz", "xxxx", "test", undefined, "apple"]`. -## Have doubt in this question ?? + #### 14. What will be the output of the following code? @@ -433,7 +411,7 @@ console.log(bar + false); - String + Boolean -> Concatenation - String + String -> Concatenation -## Have doubt in this question ?? + #### 15. What will be the output of the following code? @@ -444,7 +422,7 @@ console.log(y); > Above code will output `undefined` as output. According to `associativity` rule operator with the same precedence are processed based on their associativity property of operator. Here associativity of the assignment operator is `Right to Left` so first `typeof y` will evaluate first which is `undefined` and assigned to `z` and then `y` would be assigned the value of z and then `z` would be assign value `1`. -## Have doubt in this question ?? + #### 16. What will be the output of the following code? @@ -484,7 +462,7 @@ var foo = function bar() { // bar is undefined here ``` -## Have doubt in this question ?? + @@ -773,7 +751,7 @@ Unlike function calls and method calls, a constructor call `new Employee('John D The primary role of the constructor function is to initialize the object. -## Have doubt in this question ?? + @@ -822,7 +800,7 @@ In Javascript function defined inside has access to outer function variable and - Function can be pass as a parameter to another function - Function can be returned from function -## Have doubt in this question ?? + @@ -877,7 +855,7 @@ methodObject.display(); Here methodObject is an object and display is a method which is associated with methodObject. -## Have doubt in this question ?? + @@ -913,7 +891,7 @@ function testCallBack(callback) { } testCallBack(display); // Here display function is being passed as callback ``` -## Have doubt in this question ?? + ## Question 27 @@ -1018,7 +996,7 @@ console.log(MyNamespace.Singleton.getInstance().publicMethod()); The singleton implemented above is easy to understand. The singleton class maintains a static reference to the lone singleton instance and return that reference from the static getInstance() method. -## Have doubt in this question ?? + @@ -3329,7 +3307,7 @@ Answer: 1) 720 -## Have doubt in this question ?? + ##Contributing From 70d82581f8dd67fc19bfcca3eae0a4bd3a91cf69 Mon Sep 17 00:00:00 2001 From: Yuri Katkov Date: Sun, 10 Dec 2017 21:13:33 +0100 Subject: [PATCH 26/29] Update README.md formatting --- README.md | 261 +++++++++++++++++++++++------------------------------- 1 file changed, 113 insertions(+), 148 deletions(-) diff --git a/README.md b/README.md index f986eac..6f279f0 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Yuri Katkov from [Flashcards.js](http://flashcardsjs.com) became a co-author and the rights holder of the book. He will improve the questions and add some more from his collections of flashcards and will make sure to produce an unbeatable guide for frontend inteviews. -## 1. Difference between `undefined` and `not defined` in JavaScript +## Question 1. Difference between `undefined` and `not defined` in JavaScript > In JavaScript if you try to use a variable that doesn't exist and has not been declared, then JavaScript will throw an error `var name is not defined` and the script will stop execute thereafter. But If you use `typeof undeclared_variable` then it will return `undefined`. Before starting further discussion let's understand the difference between declaration and definition. @@ -37,7 +37,7 @@ console.log(y); // Output: ReferenceError: y is not defined [http://stackoverflow.com/questions/20822022/javascript-variable-definition-declaration](http://stackoverflow.com/questions/20822022/javascript-variable-definition-declaration) -## 2. What will be the output of the following code? +## Question 2. What will be the output of the following code? ```javascript var y = 1; @@ -70,7 +70,7 @@ console.log(k); // output 1function ``` -## 3. What is the drawback of creating true private in JavaScript? +## Question 3. What is the drawback of creating true private in JavaScript? > One of the drawback of creating a true private method in JavaScript is that they are very memory inefficient because a new copy of the method would be created for each instance. ```javascript @@ -103,7 +103,7 @@ Here each instance variable `emp1`, `emp2`, `emp3` has own copy of increaseSalar So as recommendation don't go for a private method unless it's necessary. -## 4.What is “closure” in javascript? Provide an example? +## Question 4. What is “closure” in javascript? Provide an example? > A closure is a function defined inside another function (called parent function) and has access to the variable which is declared and defined in parent function scope. The closure has access to variable in three scopes: @@ -146,7 +146,7 @@ innerFuncVar = y globalVar = abc ``` -## 5. Write a mul function which will properly when invoked as below syntax. +## Question 5. Write a mul function which will properly when invoked as below syntax. ```javascript console.log(mul(2)(3)(4)); // output : 24 @@ -174,7 +174,7 @@ In Javascript function defined inside has access to outer function variable and - Function can be pass as a parameter to another function - Function can be returned from function -### 6. How to empty an array in JavaScript? +## Question 6. How to empty an array in JavaScript? For instance: ```javascript @@ -245,7 +245,7 @@ while(arrayList.length) { Above implementation can also empty the array. But not recommended to use often. -### 7. How to check if an object is an array or not? +## Question 7. How to check if an object is an array or not? > The best way to find whether an object is instance of a particular class or not using `toString` method from `Object.prototype` ```javascript @@ -307,7 +307,7 @@ Array.isArray(arrayList); `Array.isArray` is supported by Chrome 5, Firefox 4.0, IE 9, Opera 10.5 and Safari 5 -#### 8. What will be the output of the following code? +## Question 8. What will be the output of the following code? ```javascript var output = (function(x) { @@ -321,7 +321,7 @@ console.log(output); > Above code will output `0` as output. `delete` operator is used to delete a property from an object. Here `x` is not an object it's **local variable**. `delete` operator doesn't affect local variable. -#### 9. What will be the output of the following code? +## Question 9. What will be the output of the following code? ```javascript var x = 1; @@ -336,7 +336,7 @@ console.log(output); > Above code will output `1` as output. `delete` operator is used to delete property from object. Here `x` is not an object it's **global variable** of type `number`. -#### 10. What will be the output of the following code? +## Question 10. What will be the output of the following code? ```javascript var x = { foo : 1}; @@ -351,7 +351,7 @@ console.log(output); > Above code will output `undefined` as output. `delete` operator is used to delete a property from an object. Here `x` is an object which has foo as a property and from self-invoking function we are deleting foo property of object `x` and after deletion we are trying to reference deleted property `foo` which result `undefined`. -#### 11. What will be the output of the following code? +## Question 11. What will be the output of the following code? ```javascript var Employee = { @@ -367,7 +367,7 @@ console.log(emp1.company); `emp1` object doesn't have **company** as its own property. you can test it `console.log(emp1.hasOwnProperty('company')); //output : false` However, we can delete company property directly from `Employee` object using `delete Employee.company` or we can also delete from `emp1` object using `__proto__` property `delete emp1.__proto__.company`. -#### 12. What is `undefined x 1` in JavaScript +## Question 12. What is `undefined x 1` in JavaScript ```javascript var trees = ["redwood", "bay", "cedar", "oak", "maple"]; @@ -380,7 +380,7 @@ when you run above code and do `console.log(trees);` in chrome developer console -#### 13. What will be the output of the following code? +## Question 13. What will be the output of the following code? ```javascript var trees = ["xyz", "xxxx", "test", "ryan", "apple"]; @@ -394,7 +394,7 @@ So when delete operator removes an array element that deleted element is not lon -#### 14. What will be the output of the following code? +## Question 14. What will be the output of the following code? ```javascript var bar = true; @@ -412,8 +412,7 @@ console.log(bar + false); - String + String -> Concatenation - -#### 15. What will be the output of the following code? +## Question 15. What will be the output of the following code? ```javascript var z = 1, y = z = typeof y; @@ -424,7 +423,7 @@ console.log(y); -#### 16. What will be the output of the following code? +## Question 16. What will be the output of the following code? ```javascript // NFE (Named Function Expression @@ -466,7 +465,7 @@ var foo = function bar() { -#### 17. What is the difference between declaring a function in below format? +## Question 17. What is the difference between declaring a function in below format? ```javascript var foo = function() { @@ -534,7 +533,7 @@ if(testCondition) {// If testCondition is true then ``` -#### 18. what is function hoisting in JavaScript? +## Question 18. what is function hoisting in JavaScript? **Function Expression** ```javascript @@ -570,7 +569,7 @@ foo = function foo() { foo(); // Now foo is defined here ``` -#### 19. What will be the output of the following code? +## Question 19. What will be the output of the following code? ```javascript var salary = "1000$"; @@ -599,7 +598,7 @@ var salary = "1000$"; })(); ``` -#### 20. What is the `instanceof` operator in JavaScript? what would be the output of the following code? +## Question 20. What is the `instanceof` operator in JavaScript? what would be the output of the following code? ```javascript function foo() { @@ -647,7 +646,7 @@ So the `new foo() instanceof foo` return `false`; Ref Link: [http://stackoverflow.com/questions/2449254/what-is-the-instanceof-operator-in-javascript](http://stackoverflow.com/questions/2449254/what-is-the-instanceof-operator-in-javascript) -#### 21. If we have JavaScript associative array as below code: +## Question 21. If we have JavaScript associative array as below code: ```javascript var counterArray = { @@ -696,8 +695,7 @@ console.log(Object.length(counterArray)); **Bonus**: We can also use `Underscore` (recommended, as it's lightweight) to calculate object length. -## Question 22 -### Difference between `Function`, `Method` and `Constructor` calls in JavaScript. +## Question 22. Difference between `Function`, `Method` and `Constructor` calls in JavaScript. If your are familiar with Object-oriented programming, More likely familiar to thinking of functions, methods, and class constructors as three separate things. But In JavaScript, these are just three different usage patterns of one single construct. functions : The simplest usages of function call: @@ -752,11 +750,7 @@ Unlike function calls and method calls, a constructor call `new Employee('John D The primary role of the constructor function is to initialize the object. - - - -## Question 23 -### What would be the output of the following code? +## Question 23. What would be the output of the following code? ```javascript function User(name) { @@ -771,8 +765,7 @@ The output of above code would be `USA`. Here `new User("xyz")` creates a brand Let say `new User("xyz")` crated a object called `foo` and returned now `foo["location"]` would be assigned value as `USA` and `person` is referencing to `foo["location"]`. -## Question 24 -### Write a mul function which will output when invoked as below syntax. +## Question 24. Write a mul function which will output when invoked as below syntax. ```javascript console.log(mul(2)(3)(4)); // output : 24 @@ -804,8 +797,7 @@ In Javascript function defined inside has access to outer function variable and -## Question 25 -### What is the difference between a method and a function in javascript? +## Question 25. What is the difference between a method and a function in javascript? A function is a piece of code that is called by name and function itself not associated with any object and not defined inside any object. It can be passed data to operate on (i.e. parameter) and can optionally return data (the return value). ```javascript @@ -859,8 +851,7 @@ Here methodObject is an object and display is a method which is associated with -## Question 26 -### What is JavaScript Self-Invoking anonymous function or Self-Executing anonymous function. +## Question 26. What is JavaScript Self-Invoking anonymous function or Self-Executing anonymous function. A `self-invoking` anonymous function also called `self-executing anonymous function` runs immediately or automatically when we define it and self-invoking anonymous function doesn't have any name at all. Self-Invoking anonymous function syntax: ```javascript @@ -894,8 +885,7 @@ testCallBack(display); // Here display function is being passed as callback -## Question 27 -### Describe Singleton Pattern In JavaScript? +## Question 27. Describe Singleton Pattern In JavaScript? The singleton pattern is the most commonly used design pattern and one that you will probably is more than any others. It provides a great way to wrap the code into a logical unit that can be accessed through a single variable. The Singleton design pattern is used when only one instance of an object is needed throughout the lifetime of an application. In JavaScript, there is a different way to achieve singleton object than any other object oriented supported language (Java, C++). In JavaScript Singleton pattern have many uses, they can be used for NameSpacing, which reduce the number of global variables in your page (prevent from polluting global space), organizing the code in a consistent manner, which increase the readability and maintainability of your pages. There are two important points in the traditional definition of Singleton pattern: @@ -1000,8 +990,7 @@ The singleton implemented above is easy to understand. The singleton class maint -## Question 28 -##### What are the way by which we can create object in JavaScript ? +## Question 28. What are the way by which we can create object in JavaScript ? **Method 1:** `Function Based` @@ -1064,8 +1053,7 @@ employee.getName = function(){ ``` **Note:** As a best practices object literal way is used to create object over this method. -## Question 29 -##### Write a function called deepClone which takes an object and creates a object copy of it. +## Question 29. Write a function called deepClone which takes an object and creates a object copy of it. ``` javascript var newObject = deepClone(obj); @@ -1103,8 +1091,7 @@ var personalDetail = { ``` So when we do deep clone then we should copy every property (including the nested object). -## Question 30 -##### Best way to detect `undefined` object property in JavaScript. +## Question 30. Best way to detect `undefined` object property in JavaScript. > Suppose we have given an object `person` @@ -1132,8 +1119,7 @@ if(typeof person.salary === 'undefined'){ console.log("salary is undefined here because we haven't declared"); } ``` -## Question 31 -##### Write a function called `Clone` which takes an object and creates a object copy of it but not copy deep property of object. +## Question 31. Write a function called `Clone` which takes an object and creates a object copy of it but not copy deep property of object. ```javascript var objectLit = {foo : 'Bar'}; @@ -1153,8 +1139,7 @@ function Clone(object){ } ``` -## Question 32 -##### Best way to detect `undefined` object property in JavaScript. +## Question 32. Best way to detect `undefined` object property in JavaScript. > Suppose we have given an object `person` @@ -1182,8 +1167,7 @@ if(typeof person.salary === 'undefined'){ console.log("salary is undefined here because we haven't declared"); } ``` -## Question 33 -##### How to check whether a key exist in a JavaScript object or not. +## Question 33. How to check whether a key exist in a JavaScript object or not. >Let say we have `person` object with property **name** and **age** @@ -1220,8 +1204,7 @@ console.log(person.hasOwnProperty('name')); // print true console.log(person.hasOwnProperty('salary')); // print false ``` -## Question 34 -##### Best way to detect `undefined` object property in JavaScript. +## Question 34. Best way to detect `undefined` object property in JavaScript. > Suppose we have given an object `person` @@ -1249,8 +1232,7 @@ if(typeof person.salary === 'undefined'){ console.log("salary is undefined here because we haven't declared"); } ``` -## Question 35 -##### How to check whether a key exist in a JavaScript object or not. +## Question 35. How to check whether a key exist in a JavaScript object or not. >Let say we have `person` object with property **name** and **age** @@ -1287,8 +1269,7 @@ console.log(person.hasOwnProperty('name')); // print true console.log(person.hasOwnProperty('salary')); // print false ``` -## Question 36 -##### What is best way to detect an arrays object on JavaScript ? +## Question 36. What is best way to detect an arrays object on JavaScript ? >We always encounter in such situation where we need to know whether value is type of array or not. @@ -1355,8 +1336,7 @@ function(value){ } ``` -## Question 37 -##### Best way to detect reference values of any type in JavaScript ? +## Question 37. Best way to detect reference values of any type in JavaScript ? > In Javascript Object are called as reference type, Any value other then primitive is definitely a reference type. There are several built-in reference type such as **Object**, **Array**, **Function**, **Date**, **null** and **Error**. @@ -1398,8 +1378,7 @@ console.log(emp1 instanceof Employee); // true console.log(emp1 instanceof Object); // true ``` -## Question 38 -##### Describe Object-Based inheritance in JavaScript. +## Question 38. Describe Object-Based inheritance in JavaScript. > Object-based inheritance also called prototypal inheritance in which we one object inherit from another object without invoking a constructor function. @@ -1450,8 +1429,7 @@ In above example, emp1 is created with it's own value for name, so calling **dis >Object created in this manner give you full control over newly created object. You are free to add, remove any properties and method you want. -## Question 39 -##### Describe Type-Based inheritance in JavaScript. +## Question 39. Describe Type-Based inheritance in JavaScript. >Type-based inheritance works with constructor function instead of object, It means we need to call constructor function of the object from which you want to inherit. @@ -1512,8 +1490,7 @@ console.log(name in obj); // true ``` Type-based inheritance is best used with developer defined constructor function rather than natively in JavaScript. In addition to this also allows flexibility in how we create similar type of object. -## Question 40 -##### How we can prevent modification of object in JavaScript ?. +## Question 40. How we can prevent modification of object in JavaScript ?. > ECMAScript 5 introduce several methods to prevent modification of object which lock down object to ensure that no one, accidentally or otherwise, change functionality of Object. @@ -1623,8 +1600,7 @@ delete employee.name; // fails silently unless it's in strict mode ``` -## Question 44 -##### Write a log function which will add prefix `(your message)` to every message you log using console.log ? +## Question 44. Write a log function which will add prefix `(your message)` to every message you log using console.log ? > For example, If you log `console.log("Some message")` then output should be **(your message) Some message** Logging error message or some informative message is always required when you dealing with client side JavaScript using console.log method. Some time you want to add some prefix to identify message generated log from your application hence you would like to prefix your app name in every console.log. @@ -1649,8 +1625,7 @@ console.log(appLog("Some error message")); //output of above console: 'your app name Some error message' ``` -## Question 45 -##### Write a function which will test string as a literal and as an object ? +## Question 45 . Write a function which will test string as a literal and as an object ? For example: We can create string using string literal and using String constructor function. @@ -1672,8 +1647,7 @@ For example: We can create string using string literal and using String construc console.log(isString(ltrlStr)); // true console.log(isString(objStr)); // true ``` -## Question 46 -##### What is typical use case for anonymous function in JavaScript ? +## Question 46 . What is typical use case for anonymous function in JavaScript ? > Anonymous functions basically used in following scenario. @@ -1736,8 +1710,7 @@ If your answer is yes then go and create named function rather anonymous functio 1. It can reduce a bit of code, particularly in recursive function and in callback function. 2. Avoid needless global namespace pollutions. -## Question 47 -##### How to set a default parameter value ? +## Question 47 . How to set a default parameter value ? > If you are coming from python/c# you might be using default value for function parameter incase value(formal parameter) has not been passed. For Instance : @@ -1796,8 +1769,7 @@ sentEmail({ }, 'Yahoo Mail'); ``` -## Question 48 -##### Write code for merge two JavaScript Object dynamically. +## Question 48. Write code for merge two JavaScript Object dynamically. > Let say you have two object ```javascript @@ -1846,8 +1818,7 @@ function merge(toObj, fromObj) { } } ``` -## Question 49 -##### What is non-enumerable property in JavaScript and how can create ? +## Question 49. What is non-enumerable property in JavaScript and how can create ? >Object can have properties that don't show up when you iterate through object using for...in loop or using Object.keys() to get an array of property names. This properties is know as non-enumerable properties. @@ -1894,8 +1865,7 @@ Changing non-enumerable property value will return error in `strict mode`. In no **Object.defineProperty()** is also let you create read-only properties as we saw above, we are not able to modify phoneNo value of a person object. -## Question 50 -##### What is Function binding ? +## Question 50. What is Function binding ? > Function binding falls in advance JavaScript category and this is very popular technique to use in conjunction with event handler and callback function to preserve code execution context while passing function as a parameter. @@ -1936,11 +1906,11 @@ btn.addEventListener('click', clickHandler.handleClick.bind(clickHandler)); `bind` method is available to all the function similar to call and apply method which take argument value of `this`. -#Objective Question +# Coding Questions ## Hoisting -###1. console.log(employeeId); +### 1. console.log(employeeId); 1. Some Value 2. Undefined @@ -1949,7 +1919,7 @@ btn.addEventListener('click', clickHandler.handleClick.bind(clickHandler)); Answer: 4) ReferenceError: employeeId is not defined -###2. What would be the output of following code? +### 2. What would be the output of following code? ```javascript console.log(employeeId); @@ -1963,7 +1933,7 @@ var employeeId = '19000'; Answer: 2) undefined -###3. What would be the output of following code? +### 3. What would be the output of following code? ```javascript var employeeId = '1234abe'; @@ -1980,7 +1950,7 @@ var employeeId = '1234abe'; Answer: 2) undefined -###4. What would be the output of following code? +### 4. What would be the output of following code? ```javascript var employeeId = '1234abe'; @@ -2000,7 +1970,7 @@ var employeeId = '1234abe'; Answer: 2) undefined -###5. What would be the output of following code? +### 5. What would be the output of following code? ```javascript (function() { @@ -2018,7 +1988,7 @@ Answer: 2) undefined Answer: 1) undefined -###6. What would be the output of following code? +### 6. What would be the output of following code? ```javascript var employeeId = 'abc123'; @@ -2037,7 +2007,7 @@ console.log(employeeId); Answer: 2) '123bcd' -###7. What would be the output of following code? +### 7. What would be the output of following code? ```javascript var employeeId = 'abc123'; @@ -2059,7 +2029,7 @@ console.log(employeeId); Answer: 3) 'abc123' -###8. What would be the output of following code? +### 8. What would be the output of following code? ```javascript var employeeId = 'abc123'; @@ -2082,7 +2052,7 @@ foo(); Answer: 2) 'function' -###9. What would be the output of following code? +### 9. What would be the output of following code? ```javascript function foo() { @@ -2104,7 +2074,7 @@ foo(); Answer: 1) undefined -###10. What would be the output of following code? +### 10. What would be the output of following code? ```javascript (function foo() { @@ -2130,7 +2100,7 @@ Answer: 3) function function ## Object -###1. What would be the output of following code ? +### 1. What would be the output of following code ? ```javascript (function() { @@ -2157,7 +2127,7 @@ Answer: 3) function function Answer: 3) ["name", "salary", "country", "phoneNo"] -###2. What would be the output of following code ? +### 2. What would be the output of following code ? ```javascript (function() { @@ -2184,7 +2154,7 @@ Answer: 3) ["name", "salary", "country", "phoneNo"] Answer: 4) ["name", "salary", "country"] -###3. What would be the output of following code ? +### 3. What would be the output of following code ? ```javascript (function() { @@ -2207,7 +2177,7 @@ Answer: 4) ["name", "salary", "country"] Answer: 2) false false -###4. What would be the output of following code ? +### 4. What would be the output of following code ? ```javascript (function() { @@ -2224,7 +2194,7 @@ Answer: 2) false false Answer: 2) false false -###5. What would be the output of following code ? +### 5. What would be the output of following code ? ```javascript (function() { @@ -2245,7 +2215,7 @@ Answer: 2) false false Answer: 2) false false -###6. What would be the output of following code ? +### 6. What would be the output of following code ? ```javascript (function() { @@ -2264,7 +2234,7 @@ Answer: 2) false false Answer: 2) false false -###7. What would be the output of following code ? +### 7. What would be the output of following code ? ```javascript (function() { @@ -2283,7 +2253,7 @@ Answer: 2) false false Answer: 4) true true -###8. What would be the output of following code ? +### 8. What would be the output of following code ? ```javascript (function() { @@ -2304,7 +2274,7 @@ Answer: 4) true true Answer: 3) true true true true -###9. What would be the output of following code ? +### 9. What would be the output of following code ? ```javascript (function() { @@ -2324,7 +2294,7 @@ Answer: 3) true true true true Answer: 2) bar bar -###10. What would be the output of following code ? +### 10. What would be the output of following code ? ```javascript (function() { @@ -2346,7 +2316,7 @@ Answer: 2) bar bar Answer: 3) foo foo -###11. What would be the output of following code ? +### 11. What would be the output of following code ? ```javascript (function() { @@ -2370,7 +2340,7 @@ Answer: 2) undefined undefined ## Array -###1. What would be the output of following code? +### 1. What would be the output of following code? ```javascript (function() { @@ -2387,7 +2357,7 @@ Answer: 2) undefined undefined Answer: 3) ["100"] 1 -###2. What would be the output of following code? +### 2. What would be the output of following code? ```javascript (function() { @@ -2408,7 +2378,7 @@ Answer: 3) ["100"] 1 Answer: 1) [] [] [Array[5]] 1 -###3. What would be the output of following code? +### 3. What would be the output of following code? ```javascript (function () { @@ -2426,7 +2396,7 @@ Answer: 1) [] [] [Array[5]] 1 Answer: 1) 11 -###4. What would be the output of following code? +### 4. What would be the output of following code? ```javascript (function(){ @@ -2444,7 +2414,7 @@ Answer: 1) 11 Answer: 3) 6 -###5. What would be the output of following code? +### 5. What would be the output of following code? ```javascript (function(){ @@ -2462,7 +2432,7 @@ Answer: 3) 6 Answer: 1) [ 'dog', 'rat', 'goat', 'cow', 'horse', 'cat' ] -###6. What would be the output of following code? +### 6. What would be the output of following code? ```javascript (function(){ @@ -2481,7 +2451,7 @@ Answer: 1) [ 'dog', 'rat', 'goat', 'cow', 'horse', 'cat' ] Answer: 1) 1 -1 -1 4 -###7. What would be the output of following code? +### 7. What would be the output of following code? ```javascript (function(){ @@ -2499,7 +2469,7 @@ Answer: 1) 1 -1 -1 4 Answer: 2) 1 6 -1 -###8. What would be the output of following code? +### 8. What would be the output of following code? ```javascript (function(){ @@ -2524,7 +2494,7 @@ Answer: 2) 1 6 -1 Answer: 3) [ 2, 4, 8, 12, 16 ] true -###9. What would be the output of following code? +### 9. What would be the output of following code? ```javascript (function(){ @@ -2563,7 +2533,7 @@ Answer: 1) [ 2, '12', true ] [ 2, '12', true ] [ 2, '12', true ] -###10. What would be the output of following code? +### 10. What would be the output of following code? ```javascript (function(){ @@ -2603,7 +2573,7 @@ Answer: 1) [ 'bar', 'john', 'ritz' ] [] [ 'foo', 'bar', 'john', 'ritz' ] -###11. What would be the output of following code? +### 11. What would be the output of following code? ```javascript (function(){ @@ -2621,7 +2591,7 @@ Answer: 1) [ 'bar', 'john', 'ritz' ] Answer: 1. [ 'bar', 'john' ] [] [ 'foo' ] -###12. What would be the output of following code? +### 12. What would be the output of following code? ```javascript (function(){ @@ -2640,7 +2610,7 @@ Answer: 3. [ 15, 16, 2, 23, 42, 8 ] ## Function: -###1. What would be the output of following code ? +### 1. What would be the output of following code ? ```javascript function funcA(){ @@ -2665,7 +2635,7 @@ console.log(funcA()); Answer: 1) -###2. What would be the output of following code ? +### 2. What would be the output of following code ? ```javascript var obj = { @@ -2685,7 +2655,7 @@ console.log(obj.innerMessage); Answer: 4) undefined true -###3. What would the output of following code ? +### 3. What would the output of following code ? ```javascript var obj = { @@ -2705,7 +2675,7 @@ console.log(obj.innerMessage()); Answer: 1) Hello -###4. What would the output of following code ? +### 4. What would the output of following code ? ```javascript var obj = { @@ -2726,7 +2696,7 @@ console.log(obj.innerMessage()); Answer: 3) undefined -###5. What would the output of following code ? +### 5. What would the output of following code ? ```javascript var obj = { @@ -2748,7 +2718,7 @@ console.log(obj.innerMessage()); Answer: 2) 'Hello' -###6. What would the output of following code ? +### 6. What would the output of following code ? ```javascript function myFunc(){ @@ -2766,7 +2736,7 @@ console.log(myFunc()); Answer: 3) undefined -###7. What would the output of following code ? +### 7. What would the output of following code ? ```javascript function myFunc(){ @@ -2784,7 +2754,7 @@ console.log(myFunc()); Answer: 2) 'Hi John' -###8. What would the output of following code ? +### 8. What would the output of following code ? ```javascript function myFunc() { @@ -2801,7 +2771,7 @@ console.log(myFunc()); Answer: 2) 'Hi John' -###9. What would the output of following code ? +### 9. What would the output of following code ? ```javascript function myFunc(param1,param2) { @@ -2819,7 +2789,7 @@ console.log(myFunc("a","b","c","d")); Answer: a) 2 2 2 -###10. What would the output of following code ? +### 10. What would the output of following code ? ```javascript function myFunc() { @@ -2839,7 +2809,7 @@ Answer: 2) 0 2 4 ## Object Oriented -###1. What would the output of following code ? +### 1. What would the output of following code ? ```javascript function Person(name, age){ @@ -2869,7 +2839,7 @@ Answer: 1) John Person ## Scopes -###1. What would the output of following code ? +### 1. What would the output of following code ? ```javascript function passWordMngr() { @@ -2892,7 +2862,7 @@ console.log(userInfo.userName); Answer: 3) 12345678 undefined -###2. What would the output of following code ? +### 2. What would the output of following code ? ```javascript var employeeId = 'aq123'; @@ -2909,7 +2879,7 @@ console.log(Employee.employeeId); Answer: 4) undefined -###3. What would the output of following code ? +### 3. What would the output of following code ? ```javascript var employeeId = 'aq123'; @@ -2931,7 +2901,7 @@ console.log(new Employee().employeeId); Answer: 2) bq1uy 1BJKSJ bq1uy -###4. What would the output of following code ? +### 4. What would the output of following code ? ```javascript var employeeId = 'aq123'; @@ -2954,7 +2924,7 @@ Answer: 1) foo123 aq123 ## Call, Apply, Bind -###1. What would the output of following code ? +### 1. What would the output of following code ? ```javascript (function() { @@ -2973,7 +2943,7 @@ Answer: 1) foo123 aq123 Answer: 4) [ 'W', 'o', 'r', 'l', 'd' ] -###2. What would the output of following code ? +### 2. What would the output of following code ? ```javascript (function() { @@ -3004,7 +2974,7 @@ Answer: 4) [ 'W', 'o', 'r', 'l', 'd' ] Answer: 1) Total amount left in account: 5600 Total amount left in account: 5300 -###3. What would the output of following code ? +### 3. What would the output of following code ? ```javascript (function() { @@ -3036,7 +3006,7 @@ Answer: 1) Total amount left in account: 5600 Total amount left in account: 5300 Answer: 1) 5600 5300 5100 -###4. What would the output of following code ? +### 4. What would the output of following code ? ```javascript (function() { @@ -3068,7 +3038,7 @@ Answer: 1) 5600 5300 5100 Answer: 2) 3600 3300 3100 -###5. What would the output of following code ? +### 5. What would the output of following code ? ```javascript (function greetNewCustomer() { @@ -3085,7 +3055,7 @@ Answer: 2) 3600 3300 3100 Answer: 1) Hello John -###6. What would the output of following code ? +### 6. What would the output of following code ? ```javascript (function greetNewCustomer() { @@ -3104,7 +3074,7 @@ Answer: 1) Hello John ## Callback Function -###1. What would the output of following code ? +### 1. What would the output of following code ? ```javascript function getDataFromServer(apiUrl){ @@ -3129,7 +3099,7 @@ getDataFromServer('www.google.com').then(function(name){ Answer: 1) John -###2. What would the output of following code ? +### 2. What would the output of following code ? ```javascript (function(){ @@ -3177,7 +3147,7 @@ Answer: 1) [ 2, 8, 15, 16, 23, 42 ] ## Return Statement -###1. What would the output of following code ? +### 1. What would the output of following code ? ```javascript (function(){ @@ -3199,7 +3169,7 @@ Answer: 1) [ 2, 8, 15, 16, 23, 42 ] Answer: 4) Uncaught TypeError: Cannot read property 'fullName' of undefined -###2. What would the output of following code ? +### 2. What would the output of following code ? ```javascript function getNumber(){ @@ -3217,7 +3187,7 @@ console.log(numb); Answer: 1) 5 -###3. What would the output of following code ? +### 3. What would the output of following code ? ```javascript function getNumber(){ @@ -3235,7 +3205,7 @@ console.log(numb); Answer: 2) undefined -###4**. What would the output of following code ? +### 4**. What would the output of following code ? ```javascript function mul(x){ @@ -3257,7 +3227,7 @@ console.log(mul(2)(3)[1](4)); Answer: 1) 6, 10 -###5**. What would the output of following code ? +### 5**. What would the output of following code ? ```javascript function mul(x) { @@ -3281,7 +3251,7 @@ console.log(mul(2)(3).sum(4)); Answer: 1) 6, 10 -###6. What would the output of following code ? +### 6. What would the output of following code ? ```javascript function mul(x) { @@ -3310,17 +3280,12 @@ Answer: 1) 720 -##Contributing - -I'm always welcome to feedback on how the book can be improved, and more questions can be added. If you think you have some question then please add that and open a pull request. - -####Note: All contributor to this book will be added as contributor in Book Last page by default, So if you have contributed and don't wanted to be included then please write an email to me at nihantanu@gmail.com - -##For any other query: +## Contributing +We always appreciate your feedback on how the book can be improved, and more questions can be added. If you think you have some question then please add that and open a pull request. -##License +## License This book is released under a Creative Commons Attribution-Noncommercial- No Derivative Works 3.0 United States License. From 9ea66525fd7d32d536b935ff64aa532cd4bbf72b Mon Sep 17 00:00:00 2001 From: Yuri Katkov Date: Thu, 28 Dec 2017 01:15:06 +0100 Subject: [PATCH 27/29] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 6f279f0..6e80e5f 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ # 123-JavaScript-Interview-Questions +This Book will be completed by June 2018 and available to buy. If you want me to sent early copy of this book then please add your name and email address in google form here [Google Form](https://goo.gl/forms/c8ubV1tWBBdz6fJP2). + + ## Great news! Yuri Katkov from [Flashcards.js](http://flashcardsjs.com) became a co-author and the rights holder of the book. He will improve the questions and add some more from his collections of flashcards and will make sure to produce an unbeatable guide for frontend inteviews. From 15042d56acf92a0f3954e3822e842cbeb37ff2f9 Mon Sep 17 00:00:00 2001 From: Yuri Katkov Date: Sat, 30 Dec 2017 15:33:26 +0100 Subject: [PATCH 28/29] Update README.md replaced duplicated questions with a stub --- README.md | 96 ++----------------------------------------------------- 1 file changed, 3 insertions(+), 93 deletions(-) diff --git a/README.md b/README.md index 6e80e5f..034efdf 100644 --- a/README.md +++ b/README.md @@ -768,35 +768,7 @@ The output of above code would be `USA`. Here `new User("xyz")` creates a brand Let say `new User("xyz")` crated a object called `foo` and returned now `foo["location"]` would be assigned value as `USA` and `person` is referencing to `foo["location"]`. -## Question 24. Write a mul function which will output when invoked as below syntax. - -```javascript -console.log(mul(2)(3)(4)); // output : 24 -console.log(mul(4)(3)(4)); // output : 48 -``` - -Below is code followed by an explanation how it works: - -```javascript -function mul (x) { - return function (y) { // anonymous function - return function (z) { // anonymous function - return x * y * z; - }; - }; -} -``` - -Here `mul` function accept the first argument and return anonymous function which take the second parameter and return anonymous function which take the third parameter and return multiplication of arguments which is being passed in successive. - -In Javascript function defined inside has access to outer function variable and function is a first class object so it can be returned by a function as well and passed as the argument in another function. -- A function is an instance of the Object type -- A function can have properties and has a link back to its constructor method -- Function can be stored as variable -- Function can be pass as a parameter to another function -- Function can be returned from function - - +## Question 24. Suggest your question! @@ -1207,70 +1179,8 @@ console.log(person.hasOwnProperty('name')); // print true console.log(person.hasOwnProperty('salary')); // print false ``` -## Question 34. Best way to detect `undefined` object property in JavaScript. - -> Suppose we have given an object `person` - -```javascript -var person = { - name: 'Nishant', - age : 24 -} -``` -here `person` object has `name` and `age` property. Now we are trying to access **salary** property which we haven't declared on person object so while accessing it will return undefined. So how we will ensure whether property is undefined or not before performing some operation over it. - -**Explanation:** - -We can use `typeof` operator to check undefined - -```javascript -if(typeof someProperty === 'undefined'){ - console.log('something is undefined here'); -} -``` -Now we are trying to access salary property of person object. - -```javascript -if(typeof person.salary === 'undefined'){ - console.log("salary is undefined here because we haven't declared"); -} -``` -## Question 35. How to check whether a key exist in a JavaScript object or not. - ->Let say we have `person` object with property **name** and **age** - -```javascript -var person = { - name: 'Nishant', - age: 24 -} -``` -Now we want to check whether `name` property exist in `person` object or not ? - -In JavaScript object can have own property, in above example name and age is own property of person object. Object also have some of inherited property of base object like toString is inherited property of person object. - -So how we will check whether property is own property or inherited property. - -Method 1: We can use `in` operator on objet to check own property or inherited property. - -```javascript -console.log('name' in person); // checking own property print true -console.log('salary' in person); // checking undefined property print false -``` -`in` operator also look into inherited property if it doesn't find property defined as own property. For instance If I check existence of toString property as we know that we haven't declared this property on person object so `in` operator look into there base property. - -Here - -```javascript -console.log('toString' in person); // Will print true -``` -If we want to test property of object instance not inherited properties then we will use `hasOwnProperty` method of object instance. - -```javascript -console.log(person.hasOwnProperty('toString')); // print false -console.log(person.hasOwnProperty('name')); // print true -console.log(person.hasOwnProperty('salary')); // print false -``` +## Question 34. Suggest your question! +## Question 35. Suggest your question! ## Question 36. What is best way to detect an arrays object on JavaScript ? From c21f5f0dce91e914fb9dd403ec4d2f58f2ed9fe9 Mon Sep 17 00:00:00 2001 From: Yuri Katkov Date: Sat, 30 Dec 2017 15:36:30 +0100 Subject: [PATCH 29/29] Update README.md #13 fixed typo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 034efdf..238004a 100644 --- a/README.md +++ b/README.md @@ -1320,8 +1320,8 @@ emp1.displayName = function() { console.log('xyz-Anonymous'); }; -employee.displayName();// "xyz-Anonymous" -emp1.displayName(); // "Nishant" +employee.displayName(); //Nishant +emp1.displayName();//xyz-Anonymous ``` In addition to this **Object.create()** method also allows to specify a second argument which is an object containing additional properties and methods to add to the new object.