




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document includes the explanation of Top 50+ Java script Interview Questions with Answers.
Typology: Lecture notes
1 / 8
This page cannot be seen from the preview
Don't miss anything!





Ans: JavaScript is a client-side as well as server side scripting language that can be inserted into HTML pages and is understood by web browsers. JavaScript is also an Object based Programming language
Ans: Java is a complete programming language. In contrast, JavaScript is a coded program that can be introduced to HTML pages. These two languages are not at all inter-dependent and are designed for the different intent. Java is an object - oriented programming (OOPS) or structured programming language like C++ or C whereas JavaScript is a client-side scripting language.
Ans: Following are the JavaScript Data types: Number String Boolean Object Undefined
Ans: isNan function returns true if the argument is not a number otherwise it is false.
Ans: JavaScript is faster. JavaScript is a client-side language and thus it does not need the assistance of the web server to execute. On the other hand, ASP is a server-side language and hence is always slower than JavaScript. Javascript now is also a server side language (nodejs).
Ans: Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero.
Ans: Breaking within a string statement can be done by the use of a backslash, '', at the end of the first line Example: document.write("This is \a program"); And if you change to a new line when not within a string statement, then javaScript ignores break in line. Example: var x=1, y=2,z=x+y; The above code is perfectly fine, though not advisable as it hampers debugging.
Ans: Netscape is the software company who developed JavaScript.
Ans: Undeclared variables are those that do not exist in a program and are not declared. If the program tries to read the value of an undeclared variable, then a runtime error is encountered. Undefined variables are those that are declared in the program but have not been given any value. If the program tries to read the value of an undefined variable, an undefined value is returned.
*Comment */*
Ans: 'ViewState' is specific to a page in a session. 'SessionState' is specific to user specific data that can be accessed across all pages in the web application.
Ans: === is called as strict equality operator which returns true when the two operands are having the same value without any type conversion.
Ans: To submit a form using JavaScript use document.form[0].submit(); document.form[0].submit();
Ans: Yes JavaScript does support automatic type conversion, it is the common way of type conversion used by JavaScript developers
Ans: It can be done in the following way: document.getElementById("myText").style.fontSize = "20?; or document.getElementById("myText").className = "anyclass";
Ans: There are two ways to read and write a file using JavaScript Using JavaScript extensions Using a web page and Active X objects
Ans: Following are looping structures in Javascript: For While do-while loops
Ans: Undefined value means the Variable used in the code doesn't exist
Variable is not assigned to any value Property doesn't exist
Alert Confirm and Prompt
Ans: Void(0) is used to prevent the page from refreshing and parameter "zero" is passed while calling. Void(0) is used to call another method without refreshing the page.
Ans: The following code has to be inserted to achieve the desired effect: __
Ans: All variables in the JavaScript are object data types.
Ans: An alert box displays only one button which is the OK button. But a Confirmation box displays two buttons namely OK and cancel.
Ans: Escape characters (Backslash) is used when working with special characters like single quotes, double quotes, apostrophes and ampersands. Place backslash before the characters to make it display. Example: document.write "I m a "good" boy"document.write "I m a "good" boy"
Ans: Cookies are the small test files stored in a computer and it gets created when the user visits the websites to store information that they need. Example could be User Name details and shopping cart information from the previous visits.
Ans: The pop() method is similar as the shift() method but the difference is that the Shift method works at the start of the array. Also the pop() method take the last element off of the given array and returns it. The array on which is called is then altered.
Ans: Try… Catch---finally is used to handle exceptions in the JavaScript Try{Code}Catch(exp){Code to throw an exception}Finally{Code runs either it finishes successfully or after catch}
Ans: document.write("Welcome") is used to print the text – Welcome in the screen.
Ans: Blur function is used to remove the focus from the specified object.
Ans: Variable typing is used to assign a number to a variable and then assign string to the same variable. Example is as follows: i= 8;i="john";
Ans: The 'Navigator.appversion' is used to find the name of the operating system in the client machine.
Ans: There are three types of errors: Load time errors: Errors which come up when loading a web page like improper syntax errors are known as Load time errors and it generates the errors dynamically. Run time errors: Errors that come due to misuse of the command inside the HTML language. Logical Errors: These are the errors that occur due to the bad logic performed on a function which is having different operation.
Ans: The push method is used to add or append one or more elements to the end of an Array. Using this method, we can append multiple elements by passing multiple arguments
Ans: Unshift method is like push method which works at the beginning of the array. This method is used to prepend one or more elements to the beginning of the array.
Ans: Both are almost similar. JavaScript is developed by Netscape and Jscript was developed by Microsoft.
Ans: Strict mode is a way to introduce better error-checking into your code. When you use strict mode, you cannot use implicitly declared variables, or assign a value to a read-only property, or add a property to an object that is not extensible. You can enable strict mode by adding “use strict” at the beginning of a file, a program, or a function.
Ans: A prompt box is a box which allows the user to enter input by providing a text box. The prompt() method displays a dialog box that prompts the visitor for input. 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.
Ans: NaN is a short form of Not a Number. Since NaN always compares unequal to any number, including NaN, it is usually used to indicate an error condition for a function that should return a valid number. When a string or something else is being converted into a number and that cannot be done, then we get to see NaN.
Ans: Undeclared variables are those that do not exist in a program and are not declared. If the program tries to read the value of an undeclared variable, then a runtime error is encountered. Undefined variables are those that are declared in the program but have not been given any value. If the program tries to read the value of an undefined variable, an undefined value is returned.