Skip to main content

Interview Questions of JavaScript

Introduction: JavaScript is a very popular and powerful client-side scripting language, which are used by every developer. Initially, the motto to implement it was to make dynamic pages and web components but now the day is used in a wide area of software development on the client-side and on the server-side where the JavaScript Engine is available.

Some of the few frequently asked questions come from an interview

1. What is a higher-order function in JavaScript?

In JavaScript, the higher-order function is a kind of function that can accept another function as an argument

or returns a function as a return value or both, just like the delegates in .net.

const varfirstOrderFunction = () => console.log ('HI!! this is first order');

const varHigherOrderFunction = ReturnFirstOrderFunction => ReturnFirstOrderFunction();

varHigherOrderFunction(varfirstOrderFunction);

2. What is Immediately Invoked Function Expression(IIFE) in JavaScript?

It is a JavaScript function Immediately Invoked Function Expression (IIFE) that runs as soon as it is defined.

the way of writing, the signature of it would be as below,

(function () {

      // write some code

    } )();

The primary reason to use an Immediately Invoked Function Expression is to obtain data privacy because any variables declared within the Immediately Invoked Function Expression cannot be accessed by the outside world.

If you try to access variables with IIFE then it throws an error as below,

(function () {

         var objMessage = "Immediately Invoked Function Expression";

          console.log(objMessage);

        } )();

console.log(objMessage);

3. What is the difference between == and === in JavaScript
Both are the operators and used for the comparison of two values
whereas == is used two compare the only value of the variable but === is used to compare value and type of variable.

4. How to create an object in JavaScript?
There are several ways to create objects in JavaScript, some of the few we can see here.
1. Object Constructor: var myObject = new Object()
2. Object Create: var myObjectCreate = Object.create(null)
3. Object literal: var myObjectLitteral = {}
4. Functional Constructor:
function FunctionalConstructor(name) = { this.name = name,
this.age = 28}
var myObject = new FunctionalConstructor("Vishal Thakur")
5. Prototype: 
function FunctionPrototype(){}
FunctionPrototype.prototype.name = "Vishal Thakur"
var myObject = new FunctionPrototype();

6. ES6 Class:
class MyClassInitialize{
   constructor(FullName) {
      this.FullName = FullName
   }
}
var myObject = new MyClassInitialize("Vishal Thakur");
7. Singleton:
var mySingletonObject = new function(){
   this.fullName = "Vishal Thakur";
}
5. What is the Prototype in JavaScript?
The prototype is a technique by that JavaScript inherit the feature of one another. it is a very large area and how it is going to work to understand, need to understand the Prototype chain.
6. What is the splice method in JavaScript?
The splice method is used to remove or delete the index value from the existing array.
Splice is modified to the existing array and return the deleted array.
let firstArray= [1, 2, 3, 4, 5];
let firstVariable= firstArray.splice(0,2); // returns [1, 2]; original array: [3, 4, 5]

7. What is the call() function in JavaScript?
The Call function is used to Invoke the method which is used with different objects. it invokes objects one by one as seperate object using this value.
var objectOfEmployee1 = {fName: 'Vishal', lName: 'Thakur'};
var objectOfEmployee2 = {fName: 'Johny', lName: 'Cruse'};
function Invoker(obj1, obj2) {
    console.log(obj1 + ' ' + this.fName + ' ' + this.lName+ ', '+ obj2);
}
Invoker.call(objectOfEmployee1, 'Good Day!!', 'How are you?'); // Good Day!! Vishal Thakur, How are you?
Invoker.call(objectOfEmployee2, 'Good Day!!', 'How are you?'); // Good Day!! Johny Cruse, How are you?

8. What is apply() function is used?
The apply() method is similar to the call() method, only the difference is to apply() takes arguments in an array, whereas call() takes it in separate arguments
const personalInfo = {
  name: function(mobile, address) {
    return this.fName + " " + this.lName + "," + mobile + "," + address;
  }
}
const employee = {
  fName:"Vishal",
  lName: "Thakur"
}
personalInfo.name.apply(employee, ["1234567890", "Indore India"]);//'Vishal Thakur,1234567890,Indore India'

9. What is the bind() method used for?
bind() method is used to pass n-number of arguments, it will return a new function, it differs from the apply() and call()

var firstEmployeeDetails = {fullName: 'Vishal Thakur', mobile: '1234567890'};
var secondEmployeeDetails = {fullName: 'Avtrit Thakur', mobile: '0912345689'};
function invoker(obj1, obj2) {
    console.log(obj1 + ' ' + this.fullName + ' ,' + this.mobile+ ', '+ obj2);
}
var varDetailsEmployee1 = invoker.bind(firstEmployeeDetails);
var varDetailsEmployee2 = invoker.bind(secondEmployeeDetails);
varDetailsEmployee1('Hello', 'Hop you are doing great!!'); // Hello Vishal Thakur ,1234567890, Hop you are doing great!!
varDetailsEmployee2('Hi', 'Have a great day!!'); //Hi Avtrit Thakur ,0912345689, Have a great day!!

10. What is the Splice() and Slice() method used in JavaScript?
the difference between both methods are below

11. What is the arrow function or lambda function in modern JavaScript?
The arrow function or lambda function is the new way of writing the code, it comes after the new standard applied from ES6, the main advantage of the arrow function is to make the code syntax shorter and create the function expression
public myFunction = () => {
        //do some line of code here
}

12. What is Hoisting in JavaScript?
The term Hoisting is used to declare the function and variable at the top of the code above its scope before the code execution
JavaScript only used declaration and skip the initialization at the top
let's take an example:

var objectMessage;
console.log(objectMessage);
objectMessage = 'The Message variable has been hoisted at the top';

13. What do we understand by a term service worker in JavaScript?
The concept of the service worker is a service that is running in the background and completely separate from web pages and apps,

14. What is web storage in JavaScript?
Web Storage is the technique used to store the information into the client web browser, it can store info in key/value pairs.
it has two types
Local Storage Techniques: It stores the data with no expiration validation and is stored for a number of months or years.
Session Storage Techniques: this technique uses to store the data for one session and data will be lost if the browser or tab was closed.

15. How many parts are in JavaScript?
JavaScript consists of 3 main parts
1. ECMAScript
2. JavaScript Engine
3. JavaScript Runtime

Comments

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. <a href="https://www.instaittech.com/services/nodejs-development/”>node JS Developer </a>

    ReplyDelete

Post a Comment

Popular posts from this blog

Interview Questions of SPFx SharePoint

What is SPFx? The SharePoint Framework (SPFx) is a web part model that provides full support for client-side SharePoint development, it is easy to integrate with SharePoint data, and extend Microsoft Teams. With the SharePoint Framework, you can use modern web technologies and tools in your preferred development environment to build productive experiences and apps that are responsive and mobile-ready. 1.  How to add SPFx web part to full-width column Answer:  You need to set  "supportsFullBleed": true, on the component.menifest.JSON 2. What is a gulp?  the term Gulp is an open-source JavaScript toolkit created by Eric Schoffstall used as a front-end web development streaming build system. Work with Node.js and npm, used for automation of time-consuming and repetitive tasks. Uses in web development like minification, concatenation, cache busting, unit testing, linting, optimization, etc 3. What is package.json in the SPFx? the term package.json file is an application’s directo

Interview Question of Advanced SharePoint SPFx

1. What is WebPack? A module bundling system built on top of Node. js framework is known as a WebPack. It is capable to handle the combination and minification of JavaScript and CSS files, also other files such as images by using plugins. WebPack is the recommended way of bundling the files in JS framework and .Net frameworks. in the SPFx it is used with React Js. 2. What is PowerShell.? PowerShell is a platform introduced by Microsoft to perform cross-platform task automation and configuration management framework, it is made up of a command-line shell, a scripting language. it can be run on Windows, Linux, and macOS. 3. What is bundling and Minification? The terms bundling and minification are the processes of code compressing, which is used to improve the load and request time, It is used in modern JavaScript frameworks and .Net frameworks. It improves the load time by reducing the number of requests to the server and reducing the size of requested such as CSS and JavaScript. it dec

Top20 - SharePoint Framework (SPFx) Interview Questions

1.  Which tool we can use to generate a SharePoint Framework (SPFx) solution? Developer can use  Yeoman to generate SharePoint Framework (SPFx) solution, it is a client-side scaffolding open-source tool to help in web-based development. 2. How developer can ensure that the solution deployed was immediately available to all site collections in SPFx?  To ensure the availability of the deployed solution on all the site collections developer has to configure  skipFeatureDeployment: true  in package-solution.json {     "solution" : {       "name" : "theultimateresources-deployment-client-side-solution" ,       "id" : "as3feca4-4j89-47f1-a0e2-78de8890e5hy" ,       "version" : "2.0.0.0" ,       "skipFeatureDeployment" : true     },     "paths" : {       "zippedPackage" : "solution/theultimateresources-deploy-true.sppkg"     }  }