Best Online Tutorials

SQL Tutorial

Free SQL Tutorial

SQL Interview Questions

SQL Practice Questions

SQL Tips & Tricks

SQL Errors

SQL Books

Angular Tutorial

Free Angular Tutorial

Angular Interview Questions

Angular Practice Questions

Angular Tips & Tricks

Angular Errors

Angular Books

Node.js Tutorial

Free Node.js Tutorial

Node.js Interview Questions

Node.js Practice Questions

Node.js Tips & Tricks

Node.js Errors

Node.js Books

React.js Tutorial

Free React.js Tutorial

React.js Interview Questions

React.js Practice Questions

React.js Tips & Tricks

React.js Errors

React.js Books

SSIS Tutorial

Free SSIS Tutorial

SSIS Interview Questions

SSIS Practice Questions

SSIS Tips & Tricks

SSIS Errors

SSIS Books

SEO Tutorial

Free SEO Tutorial

SEO Interview Questions

SEO Practice Questions

SEO Tips & Tricks

SEO Errors

SEO Books

Javascript Tutorial

Free Javascript Tutorial

Javascript Interview Questions

Javascript Practice Questions

Javascript Tips & Tricks

Javascript Errors

Javascript Books

MongoDB Tutorial

Free MongoDB Tutorial

MongoDB Interview Questions

MongoDB Practice Questions

MongoDB Tips & Tricks

MongoDB Errors

MongoDB Books

Next.js Tutorial

Free Next.js Tutorial

Next.js Interview Questions

Next.js Practice Questions

Next.js Tips & Tricks

Next.js Errors

Next.js Books

JavaScript interview questions | Part 1 

Prashant Surya  |   Oct 22, 2019  |  Views: 354
pictures

Description:


1.  What is the difference between window, document, screen in JavaScript?

window:
Window is the main JavaScript object root.
It is the global object in a browser.
It is being treated as the root of the document object model. 
We can access it as window variable in most of the browsers.

screen:
window.screen is the small information object about the physical screen dimensions of the browser.

document:
window.document or just document is the main object of the rendered document object model/DOM.



2.  What is the alternative of Document.ready in JavaScript?

var callbackFn = function(){
  // Scripts which needs to be run when the DOM is fully loaded
};


if (document.readyState === "complete" || (document.readyState !== "loading" && !document.documentElement.doScroll)) {
      callbackFn();
} else {
      document.addEventListener("DOMContentLoaded", callbackFn);
}


IF using older version of IE<=8

document.attachEvent("onreadystatechange", function(){

    // It checks if the DOM is fully loaded

  if(document.readyState === "complete"){

    // then remove the listener, to make sure it wouldn't be fired in the future

    document.detachEvent("onreadystatechange", arguments.callee);

    // Calling the actual handler callback...

    callbackFn();
    
  }
});


3.  How to clone an object in JavaScript?

Object.assign() method is used for cloning an object in JavaScript.

Example:

var x = { prop: "value"};
var y = Object.assign({}, x);



4.  What is output of undefined * 5 in JavaScript ?

Output :  NaN

undefined * 5              //NaN
null * undefined          //NaN
NaN * 2                       //NaN
3 * null                             //0
3 * "string"                  //NaN
undefined * "string"    //NaN



5.  What is the difference between the substr() and substring() functions in JavaScript?

Both are used to extract a small string part from the given string using startIndex and either by giving length or the lastIndex as the parameters.

substr:

The substr() function has the form substr (startIndex , length). It returns the substring from startIndex and returns ‘length’ number of characters.

var s = "hello";
( s.substr(1,4) == "ello" )    // true

substring:

The substring() function has the form substring (startIndex , endIndex) . It returns the substring from startIndex up to endIndex – 1.

var s = "hello";
( s.substring(1,4) == "ell" )   // true




6.  How to get the primitive value of a string in JavaScript?

valueOf() method is used to get the primitive value of a string in the JavaScript.

Example:

var wlcmVar = "Welcome to DritalConnect!"

console.log( wlcmVar.valueOf() )



7.  What are JavaScript boxes and their types?

JavaScript have three types of boxes, which are used as per the requirements.
 
alert:

It is used to show alert messages to the users.

alert("Invalid username");

confirm:

If there needs to get users confirmation, we use this.
 
confirm("Are you sure you want to delete?");   //It returns true/false

prompt:

If we need to get the user inputs, we use prompt.

var data = prompt("Enter your username","DritalConnect"); 



8.  How to empty an array in JavaScript?

There are multiple was to empty an array in the JavaScript.

By assigning an empty array:

var arr1 =[3,4,5,6];
arr1=[];


By assigning array length to 0:

var arr2 =[3,4,5,6];
arr2.length=0;


By poping the elements of the array:

var arr2 =[3,4,5,6];
while(arr.length > 0) {
    arr.pop();
}


By using .splice():

var arr =[3,4,5,6];
arr.splice(0,arr.length)



9.  Write a JavaScript method for Factorial of n length?

function factorial(n) {
  if ((n === 0) || (n === 1))
    return 1;
  else
    return (n * factorial(n - 1));
}

factorial(5)     //120



10.  What will be the output on Comparing null with undefined in JavaScript?

(null == undefined) -> true

(null === undefined) -> false





Continue reading JavaScript Interview Questions | Part 2

Comments:
Content Contributor
Prashant Surya

Prashant Surya

Software developer at Uniserve Data Technologies Pvt. Ltd.  |   Noida, Uttar Pradesh, India

I am a software developer, freelancer and trainer working on technologies likes. MEAN stack, MERN Stack, ASP.NET full stack, WebRTC, socket.io ,PWA, SQL, JavaScript, jQuery, HTML, CSS, SEO, responsive UI/UX designing... having 7 years of experience in development in multiple domains like, eCommerce, RTA, capital markets, education, real estate...


Read related articles

JavaScript interview questions | Part 2

Prashant Surya  |   Oct 22, 2019  |  Views: 232

JavaScript interview questions | Part 1

Prashant Surya  |   Oct 22, 2019  |  Views: 355

Want to sell your software ?-

If you want to sell your readymade software to the genuine clients or businessman, list your software with details and demo links.

  • Sell ERP
  • Sell Website Clones
  • Sell App Clones
  • Sell Readymade Portals
  • Sell Readymade Websites
  • Sell Mobile Apps
  • Sell Window Apps

Clients will find it using our advanced search filter and will contact you directly.

No any charge for the product lsiting.

Do you own a Company ?+

Property.sale

Buy or Sell Commercial Property+

Are you a freelancer ?+

Looking for a job ?+

Are you a Service Provider ?+

Are you a blogger ?+

Do you own an IT Institute ?+



Property.sale