101 + Advanced java interview questions for experienced professionals

101 + Advanced java interview questions for experienced professionals
Spread the love

Here is the list 101 + Advanced JavaScript Interview Questions and Answers in 2019 for freshers and experienced professionals with basic, advanced and ES5, ES6.

  1. What is JavaScript?

JavaScript, often abbreviated as JS, is a high-level, interpreted programming language that conforms to the ECMAScript specification. JavaScript has curly-bracket syntax, dynamic typing, prototype-based object-orientation, and first-class functions.

  1. Who is the founder of JavaScript?

Brendan Eich

  1. Where is JavaScript gaining so much popularity these days?

It is clearly due to the rise of web applications. The convenience of a web application where you can host it centrally and keep updating a single codebase to immediately add functionality / fix bugs for all your users is a major reason.

  1. What are the advantages of JavaScript?

The biggest advantages to a JavaScript having a ability to produce the same result on all modern browsers. Client-Side execution: No matter where you host JavaScript, Execute always on client environment to save a bandwidth and make execution process fast.

  1. What are the disadvantages of JavaScript?
  • Because the code executes on the users’ computer, in some cases it can be exploited for malicious purposes. This is one reason some people choose to disable Javascript.
  • JavaScript is sometimes interpreted differently by different browsers. Whereas server-side scripts will always produce the same output, client-side scripts can be a little unpredictable.
  1. What is the latest version of JavaScript?

The latest JavaScript version was 1.8.5. (Identical to ECMAScript 5).

  1. What is ES5?

ES5 5 is a scripting-language specification is the official name for the ECMAScript specification update published in 2009.

  1. What is ES6?

ES6 refers to version 6 of the ECMAScript programming language. ECMAScript is the standardized name for JavaScript, and version 6 is the next version after version 5, which was released in 2011.

  1. What are the latest changes in JavaScript ES6?
  • JavaScript let
  • JavaScript const
  • Exponentiation (**) (EcmaScript 2016)
  • Default parameter values
  • Array.find()
  • Array.findIndex()
  1. Enumerate the differences between Java and JavaScript?

Key differences between Java and JavaScript: Java is an OOP programming language while JavaScript is an OOP scripting language. Java creates applications that run in a virtual machine or browser while JavaScript code is run on a browser only. Java code needs to be compiled while JavaScript code are all in text.

  1. What are JavaScript Data Types?

In JavaScript there are two different kinds of data: primitives, and objects. A primitive is simply a data type that is not an object, and has no methods. In JS, there are six primitive data types: Boolean, Number, String, Null, Undefined, and Symbol.

  1. What is the use of isNaN function?

sNaN() function determines whether a value is an illegal number (Not-a-Number). This function returns true if the value equates to NaN. Otherwise it returns false.

  1. Between JavaScript and ASP Script, which is faster?

Javascript is faster than ASP script. -Since java scripting is written for client-side machines / browsers, it does not need the web server’s support for execution. – Hence it is always faster than ASP scripting. Only the computation is done on the server side. – ASP is a server side language so it does needs the assistance of the web server which is a time consuming process. – PHP, ASP etc. are all server side scripting languages that is why they are slower than the ASP script.

  1. What is negative infinity?

Number.NEGATIVE_INFINITY is a special numeric value that is returned when an arithmetic operation or mathematical function generates a negative value greater than the largest representable number

  1. Is it possible to break JavaScript code into several lines?

Yes

  1. How can you debug JavaScript?

By using:

  • JavaScript Debuggers: With a debugger, you can also set breakpoints (places where code execution can be stopped), and examine variables while the code is executing.
  • The console.log() Method: If your browser supports debugging, you can use console.log() to display JavaScript values in the debugger window.
  • The debugger Keyword: The debugger keyword stops the execution of JavaScript, and calls (if available) the debugging function.
  1. Which company developed JavaScript?

Netscape

  1. What are undeclared and undefined variables?

An undeclared variable is a when you use a variable without “declaring” it with the keywords: “var”, “let”, or “const” An undefined variable is a variable that is declared but has been assigned no value.

  1. Write the code for adding new elements dynamically?

// Wait until the window finishes loaded before executing any script

window.onload = function() {

var activityNumber = 3;

var addButton = document.getElementById(“add_activity”);

var tracklistTable = document.getElementById(“tracklist”);

addButton.onclick = function() {

tracklistTable.innerHTML += ‘<tr><td>’ + activityNumber + ‘</td><td><label>Activity Log: </label><br/><input type=”text” name=”actlog’ + activityNumber + ‘” class=”required”></td><td><label>Time: </label><br/><input type=”time” name=”time’ + activityNumber + ‘” class=”required”></td></tr>’;

activityNumber += 1;

}

}

  1. What are the global variables? How are these variable declared and what are the problems associated with using them?

global variables are those variables which can be used by more than one function in a program. global variables have to be declared outside of any function, generally at the beginning of any program. The most common problem is updating the global variable.If more than one function is trying to update the variable, then we have to be cautious that it is done in the desired manner.

  1. What is a prompt box?

A prompt box is often used if you want the user to input a value before entering a page. When a prompt box pops up, the user will have to click either “OK” or “Cancel” to proceed after entering an input value.

  1. What is ‘this’ keyword in JavaScript?

this keyword refers to an object, that object which is executing the current bit of javascript code. In other words, every javascript function while executing has a reference to its current execution context, called this. Execution context means here is how the function is called.

  1. What is callback in Javascript?

A callback is a function that is to be executed after another function has finished executing — hence the name ‘call back’. More complexly put: In JavaScript, functions are objects. … Any function that is passed as an argument is called a callback

  1. What is closure?

A closure is a feature in JavaScript where an inner function has access to the outer (enclosing) function’s variables — a scope chain. The closure has three scope chains: it has access to its own scope — variables defined between its curly brackets. it has access to the outer function’s variables.

  1. Explain timers in JavaScript?

Timer functions are higher-order functions that can be used to delay or repeat the execution of other functions (which they receive as their first argument). ); This example uses setTimeout to delay the printing of the greeting message by 4 seconds.

  1. Which symbol is used for comments in Javascript?

There are two symbols:

  • Inline comment symbol ( // )
  • Multiline comment symbol ( /* */ )
  1. What is the difference between ViewState and SessionState?

The Viewstate is stored within the page itself (in encrypted text), while the Sessionstate is stored in the server. Session is used mainly for storing user specific data [ session specific data ]. … Viewstate is the type of data that has scope only in the page in which it is used.

  1. What is === operator?

‘===’ means equality without type coersion. In other words, if using the triple equals, the values must be equal in type as well.

  1. Explain how can you submit a form using JavaScript?

In javascript onclick event , you can use form.submit() method to submit form. You can perform submit action by, submit button, by clicking on hyperlink, button and image tag etc. You can also perform javascript form submission by form attributes like id, name, class, tag name as well.

  1. Does JavaScript support automatic type conversion?

Yes

  1. How can the style/class of an element be changed?

To change all classes for an element: To alter all absolute classes with one or added new classes, set the className attribute: document.getElementById(“MyElement”).className = “MyClass”; (You can use a space-delimited account to administer assorted classes.).

  1. Explain how to read and write a file using JavaScript?

Using JavaScript extensions (runs from JavaScript Editor), or Using a web page and ActiveX objects (Internet Explorer only)

  1. What are all the looping structures in JavaScript?

In JavaScript we have the following looping statements: while – loops through a block of code while a condition is true. do…while – loops through a block of code once, and then repeats the loop while a condition is true. for – run statements a specified number of times.

  1. What is called Variable typing in Javascript?

Variable Typing. Like PHP, JavaScript is a very loosely typed language; the type of a variable is determined only when a value is assigned and can change as the variable appears in different contexts.

  1. How can you convert the string of any base to integer in JavaScript?

There are many methods to convert a string to an integer in javascript.

They are:

  • parseInt function: Takes the string to be converted and target integer base as arguments.
  • Unary plus operator: Simple method, prepend the string to be converted with a +.
  • Math.round: Converts string to integer but rounds the number to nearest whole number. Not a problem if the number is already a whole number.
  • Using Number object.
  1. Explain the difference between “==” and “===”?

JavaScript has both strict and type–converting comparisons. A strict comparison (e.g., === ) is only true if the operands are of the same type and the contents match. The more commonly-used abstract comparison (e.g. == ) converts the operands to the same type before making the comparison.

  1. What would be the result of 3+9+”5″?

“125”

  1. Explain how to detect the operating system on the client machine?

To detect the operating system on the client machine, your script can analyze the value of navigator.appVersion or navigator.userAgent .

  1. What do mean by NULL in Javascript?

It simply represents the absence of any object value (If you are from Java backgound then it could simply mean an object pointing to nothing).

  1. What is the function of delete operator?

The delete keyword deletes both the value of the property and the property itself. After deletion, the property cannot be used before it is added back again. The delete operator is designed to be used on object properties. It has no effect on variables or functions.

  1. What are all the types of Pop up boxes available in JavaScript?
  • Alert
  • Confirm
  • Prompt
  1. What is the use of Void(0)?

The JavaScript void operator evaluates the given expression and then returns a value of undefined . You may ocassionally encounter an HTML document that uses href=”JavaScript:Void(0);” within an <a> element. JavaScript void is often used when, inserting an expression into a web page may produce an unwanted side-effect.

  1. How can a page be forced to load another page in JavaScript?

The following code has to be inserted to achieve the desired effect:

location.href=“http://newhost/newpath/newfile.html”;

  1. What is the data type of variables of in JavaScript?

In JavaScript there are two different kinds of data: primitives, and objects. A primitive is simply a data type that is not an object, and has no methods. In JS, there are six primitive data types: Boolean, Number, String, Null, Undefined, and Symbol.

  1. What is the difference between an alert box and a confirmation box?

Alerts you by giving some information. It can be informative, warning, error message or anything else but just an information. Confirmation confirms you by giving some information or question. You will require to take some decision (E.g. for confirmation like “Are you sure you want to delete this employee record?”; you will require to take decision on whether you want to submit deletion of an employee record.

  1. What are escape characters?

An escape character enables you to output characters you wouldn’t normally be able to, usually because the browser will interpret it differently to what you intended. In JavaScript, the backslash ( \ ) is an escape character.

  1. What are JavaScript Cookies? How to set them ?

Cookies are small items of data, each consisting of a name and a value, stored on behalf of a website by visitors’ web browsers. In JavaScript, cookies can be accessed through the document.cookie object, but the interface provided by this object is very primitive. The example code below sets a cookie to expire on a Friday:

document.cookie = ‘cookie1=test; expires=Fri, 3 Aug 2001 20:47:11 UTC; path=/’

  1. How to set cookie time in Javascript ?

The following is an function example that sets a cookie to expire in a later date and time from now. Executing the function will set a cookie. A cookie is set by setting a value to the document.cookie object.

function setCookieTime() {

var now = new Date();

var time = now.getTime();

var expireTime = time + 1000*36000;

now.setTime(expireTime);

document.cookie = ‘cookie=ok;expires=’+now.toGMTString()+’;path=/’;

//console.log(document.cookie);

}

  1. Explain what is pop()method in JavaScript?

The pop() method removes the last element from an array and returns that element. This method changes the length of the array.

  1. Whether JavaScript has concept level scope?

Yes, it has concept level scope.

  1. Mention what is the disadvantage of using innerHTML in JavaScript?

Using inner HTML can also break the document of the JavaScript. Since no validation is required by it, any type of valid inner HTML can be used. Even broken HTML can also be used and this can cause problems.

  1. What is break and continue statements?

The break statement exits a switch statement or a loop (for, for … in, while, do … while). The continue statement breaks one iteration (in the loop) if a specified condition occurs, and continues with the next iteration in the loop.

  1. What are the two basic groups of data types in JavaScript?

In JavaScript there are two different kinds of data: primitives, and objects. A primitive is simply a data type that is not an object, and has no methods. In JS, there are six primitive data types: Boolean, Number, String, Null, Undefined, and Symbol.

  1. How generic objects can be created?

A generic object is essentially an empty blueprint for an object. You can define it anywhere in your Javascript code. You define a constructor function to create objects with a particular initial set of properties and values. Any JavaScript function can be used as a constructor.M

  1. What is the use of typeof operator?

In JavaScript, the typeof operator returns the data type of its operand in the form of a string. Operand can be any object, function or variable. … Input: typeof “geeksforgeeks” Output: string Input: typeof NaN Output: number NaN is also considered as a number.

  1. Which keywords are used to handle exceptions?

try, catch, and finally,

  1. Which keyword is used to print the text in the screen?

We have two ways to code this: InnerHTML and Document.write()

  1. How to print pages using javascript ?

JavaScript print function window.print() is used to print the content of the web pages.

  1. What is the use of blur function?

The HTMLElement.blur() method removes keyboard focus from the current element.

  1. What is variable typing?

Variable Typing. Like PHP, JavaScript is a very loosely typed language; the type of a variable is determined only when a value is assigned and can change as the variable appears in different contexts.

  1. What are the different types of errors in JavaScript?

EvalError An error has occurred in the eval() function

RangeError A number “out of range” has occurred

ReferenceError An illegal reference has occurred

SyntaxError A syntax error has occurred

TypeError A type error has occurred

URIError An error in encodeURI() has occurred

  1. What is the use of Push method in JavaScript?

The push() method adds new items to the end of an array, and returns the new length.

  1. What is unshift method in JavaScript?

The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.

  1. What is the difference between JavaScript and Jscript?

JScript is the Microsoft dialect of the ECMAScript scripting language specification. … In fact the name “JavaScript” is often used to refer to ECMAScript or JScript. Microsoft uses the name JScript for its implementation to avoid trademark issues

  1. How are object properties assigned?

By using the Object​.assign() method. The Object.assign() method is used to copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object.Ma

  1. What is the ‘Strict’ mode in JavaScript and how can it be enabled?

Strict mode is declared by adding “use strict”; to the beginning of a script or a function. Declared at the beginning of a script, it has global scope (all code in the script will execute in strict mode):

  1. What is the way to get the status of a CheckBox?

By checking the “checked” property of the CheckBox if it’s true (it’s checked) or false (it’s not checked).

  1. How can the OS of the client machine be detected?

To detect the operating system on the client machine, your script can analyze the value of navigator.appVersion or navigator.userAgent .

  1. Explain window.onload and onDocumentReady?

“window.onload” will execute code when browser has loaded the DOM tree and all other resources like images, objects, etc, while onDocumentReady allows you to execute code when only the DOM tree has been built, without waiting for images to load.

  1. How will you explain closures in JavaScript? When are they used?

A closure is the combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment). In other words, a closure gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time. To use a closure, simply define a function inside another function and expose it. To expose a function, return it or pass it to another function. The inner function will have access to the variables in the outer function scope, even after the outer function has returned.

  1. Explain the for-in loop in Javascript ?

Loops in JavaScript are used to execute the same block of code a specified number of times or while a specified condition is true. The for loop is used when you know in advance how many times the script should run.

  1. Describe the properties of an anonymous function in JavaScript?

Anonymous functions are functions that are dynamically declared at runtime. They’re called anonymous functions because they aren’t given a name in the same way as normal functions. Anonymous functions are declared using the function operator instead of the function declaration. You can use the function operator to create a new function wherever it’s valid to put an expression. For example you could declare a new function as a parameter to a function call or to assign a property of another object.

  1. What is the difference between .call() and .apply()?

Difference between call and apply is just that apply accepts parameters in the form of an array while call simply can accept a comma separated list of arguments.

  1. Define event bubbling?

Event bubbling is a type of event propagation where the event first triggers on the innermost target element, and then successively triggers on the ancestors of the target element in the same nesting hierarchy till it reaches the outermost DOM element or document object.

  1. Is JavaScript case sensitive? Give an example?

JavaScript is a case-sensitive language. This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters. The while keyword, for example, must be typed “while”, not “While” or “WHILE”. Similarly, online, Online, OnLine, and ONLINE are four distinct variable names.

  1. What boolean operators can be used in JavaScript?

Javascript generally supports the true and false values. – A Boolean() function can be used to find out if an expression is true.

  1. How can a particular frame be targeted, from a hyperlink, in JavaScript?

Using the target attribute. The Syntax is as follows:

<a target=”_blank|_self|_parent|_top|framename”>

  1. What is the role of break and continue statements?

The break statement exits a switch statement or a loop (for, for … in, while, do … while). The continue statement breaks one iteration (in the loop) if a specified condition occurs, and continues with the next iteration in the loop.

  1. Write the point of difference between web-garden and a web-farm?

When we host a web application over multiple web servers to distribute the load among them, it is called Web Farm and when one application has multiple worker processes, it is called a Web garden.

  1. How are object properties assigned?

Object​.assign() The Object.assign() method is used to copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object.

  1. What is the method for reading and writing a file in JavaScript?

Using JavaScript extensions (runs from JavaScript Editor), or Using a web page and ActiveX objects (Internet Explorer only)

  1. How are event handlers utilized in JavaScript?

An event that can be handled is something happening in a browser window, including a document loading, the user clicking a mouse button, the user pressing a key, and the browser screen changing size.

  1. Explain the role of deferred scripts in JavaScript?

defer attribute for external scripts. The boolean defer attribute on script elements allows the external JavaScript file to run when the DOM is loaded, without delaying page load first.

  1. What are the various functional components in JavaScript?

Plain or Vanilla JavaScript does not have any well known functional components.

  1. Write about the errors shown in JavaScript?

When executing JavaScript code, different errors can occur. Errors can be coding errors made by the programmer, errors due to wrong input, and other unforeseeable things.

  1. What are Screen objects?

The screen object, implementing the Screen interface, is a special object for inspecting properties of the screen on which the current window is being rendered.

  1. Explain the unshift() method?

The unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.

  1. Define unescape() and escape() functions?

unescape() computes a new string in which hexadecimal escape sequences are replaced with the character that it represents. escape() computes a new string in which certain characters have been replaced by a hexadecimal escape sequence.

  1. What are the decodeURI() and encodeURI()?

encodeURI() encodes a URI by replacing URL reserved characters with their UTF-8 encoding. decodeURI() takes an encoded string and replacing the tokens with the normal characters.

  1. Why it is not advised to use innerHTML in JavaScript?

If you’re trying to add new DOM elements inside of another DOM element.

  1. What does the following statement declare?
  1. How are JavaScript and ECMAScript related?

ECMAScript is a Standard for scripting languages. Languages like Javascript are based on the ECMAScript standard.

  1. What is namespacing in JavaScript and how is it used?

The practice of namespacing is usually to create an object literal encapsulating your own functions and variables, so as not to collide with those created by other libraries:

  1. How can JavaScript codes be hidden from old browsers that don’t support JavaScript?

Immediately after the opening <script> tag, put a one-line HTML-style comment

without the closing characters, so that the first two lines of your script would look like this:

<script language=”JavaScript”>

<!–

At the end of your script, put the following two lines:

//–></script>

  1. How to work with APIs in javascript?

By making HTTP requests and utilizing their responses on the browser or some other JavaScript environment.. Such requests include Asynchronous requests (AJAX) and form requests, using various request methods.

  1. How to work with JSON in javascript?

JSON.parse() Strings are useful for transporting but you’ll want to be able to convert them back to a JSON object on the client and/or the server side. While you can convert text to an object with the eval() function, it is not very secure, so we’ll use the JSON.parse() function instead.

  1. Does JavaScript support Regular Expressions?

Yes, JavaScript supports Regular Expressions.

  1. What is JavaScript – Image Map?

It’s an image on a web page that provides various links to navigate to other web pages or some sections of the same web page.

  1. What is typescript? How it’s related to javascript?

TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.

  1. How can you do animations in javascript?

JavaScript animations are done by programming gradual changes in an element’s style. The changes are called by a timer. When the timer interval is small, the animation looks continuous.

  1. How to redirect a URL in JavaScript?

There are a couple of ways to redirect to another webpage with JavaScript. The most popular ones are location.href and location.replace

  1. Explain higher-order functions in JavaScript?

Higher order function is the best feature of functional programming available in JavaScript. It is the function which takes a function as an argument and returns a function as a result. Some of the inbuilt higher-order functions are mapping, filtering, reduction, zipping, etc.

  1. What is difference between Array.splice() and Array.slice() method in JavaScript?
  • The array.slice() removes items from the array and then return those removed items as an array whereas array.slice() method is selected items from an array and then those elements as a new array object.
  • The splice() method affects the original array whereas slice() method doesn’t affect the original array.
  • Splice() method takes n number of arguments whereas slice() can take only two arguments.
  1. What will happen if an infinite while loop is run in Javascript?

The program will crash the browser.

  1. What is the use of let & const?

In modern javascript let & const are different ways of creating variables.Earlier in javascript, we use the var keyword for creating variables. let & const keyword is introduced in version ES6 with the vision of creating two different types of variables in javascript one is immutable and other is mutable. const: It is used to create an immutable variable. Immutable variables are variables whose value is never changed in the complete life cycle of the program. let: let is used to create a mutable variable. Mutable variables are normal variables like var that can be changed any number of time.

  1. How to convert Javascript date to ISO standard?

toISOString() method is used to convert javascript date to ISO standard.

It converts JavaScript Date object into a string, using the ISO standard.

Usage:

var date = new Date();

var n = date.toISOString();

console.log(n);

// YYYY-MM-DDTHH:mm:ss.sssZ

  1. List few difference between primitive and non primitive JavaScript data types?
  • The primitive data types are numbers, strings, Boolean, undefined, null and anything other than these data types are known as non-primitive such as objects and functions.
  • Primitive data types are immutable while non-primitives are mutable.
  • Primitives are known immutable as they can’t be changed once they created but non-primitive are changeable, means once an object is created, it can be changed.
  • Primitives data types are compared with their values, it means two values are strictly equal if they have the same data type and holds the same value.
  • Non-primitives are not compared with values. For example, if two objects have the same properties and values, they are strictly not equal.
  1. How host objects are different from native objects in JavaScript?

Host objects: These are those objects which environment gives. It means they are different for different environments. For example, browsers include objects such as windows but Node.js environments give objects such as Node List.

Native Objects: these are built-in objects in JavaScript. They are also known as Global Objects because they will be available to you independent of ay environment if you working in JavaScript.

  1. What is the difference between let and var?

Both var and let are used for variable/ method declaration in javascript but the main difference between let and var is that var is function scoped whereas let is block scoped.

  1. How to call a function in every x seconds in JavaScript?

In JavaScript, we use the function setInterval() to call any function in every x seconds. Syntax:

setInterval(function, milliseconds, param1, param2, …)

Function: it is a required parameter which includes the function to be execute. Milliseconds: required parameter which tells how often the function will execute. Others are an additional parameter.

For example:

setInterval(function (){ alert(“Hello”); }, 3000);

In the above example, this function calls hello function in very 3 seconds.

  1. How to get inner Html of an element in JavaScript?

InnerHTML property of HTML DOM is used to get inner Html of an element in JavaScript.

Example Usage:

This is inner Element

<script type=”text/javascript”>

var inner= document.getElementById(“inner”).innerHTML ;

console.log(inner); // This is inner Element

document.getElementById(“inner”).innerHTML = “Html changed!”;

var inner= document.getElementById(“inner”).innerHTML ; console.log(inner); // Html changed!

</script>

admin

admin

Leave a Reply

Your email address will not be published. Required fields are marked *