- Related
- JavaScript MCQ
- Java MCQ
- Java Interview Question
- Java Tutorial
- PHP MCQ
- PHP Interview Question
- React MCQ
- React Interview Question
- Node MCQ
- Node Interview Question
- Angular MCQ
- Angular Interview Question
- HTML MCQ
- HTML Interview Question
- CSS MCQ
- CSS Interview Question
- Python MCQ
- Python Interview Question
- TypeScript Interview Question
- MYSQL MCQ
- MYSQL Interview Question
- DotNet MCQ
- DotNet Interview Question
- C Sharp MCQ
- C Sharp Interview Question
- Go Interview Question
- Flutter MCQ
- Flutter Interview Question
- Flutter Tutorial
- Spring Framework MCQ
- Spring Framework Interview Question
- Spring Boot Interview Question
JavaScript Interview Questions
1
What is JavaScript?JavaScript is a lightweight, interpreted programming language with object-oriented capabilities that allows you to build interactivity into otherwise static HTML pages. The general-purpose core of the language has been embedded in Netscape, Internet Explorer, and other web browsers.
2
Is JavaScript a case-sensitive language?Yes, JavaScript is a case sensitive language. The language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters.
3
How can you create an object in JavaScript?JavaScript supports Object concept very well. You can create an object using the object literal as follows −
var emp = { name: "Daniel", age: 23 };
4
Can you assign an anonymous function to a variable and pass it as an argument to another function?Yes! An anonymous function can be assigned to a variable. It can also be passed as an argument to another function.
In case you are facing any challenges with these JavaScript Interview Questions, please comment on your problems in the section below.
5
What are the scopes of a variable in JavaScript?The scope of a variable is the region of your program in which it is defined. JavaScript variable will have only two scopes.
• Global Variables − A global variable has global scope which means it is visible everywhere in your JavaScript code.
• Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.
6
What is the purpose of ‘This’ operator in JavaScript?The JavaScript this keyword refers to the object it belongs to. This has different values depending on where it is used. In a method, this refers to the owner object and in a function, this refers to the global object.
7
What is Closure? Give an example.Closures are created whenever a variable that is defined outside the current scope is accessed from within some inner scope. It gives you access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created. To use a closure, simply define a function inside another function and expose it.
8
How to delete a cookie using JavaScript?If you want to delete a cookie so that subsequent attempts to read the cookie in JavaScript return nothing, you just need to set the expiration date to a time in the past. You should define the cookie path to ensure that you delete the right cookie. Some browsers will not let you delete a cookie if you don’t specify the path.
9
What is the method to change the title of a page using JavaScript?Generally, the page title varies based on the HTML document and the element structure. We can give id to an element and use code:
document.getElementById(‘page-title-id’).innerHTML=NewTitle;
10
What is Weak Set in JavaScript?The Set represents a collective of ordered and unique elements. Similar to Set, Weak Set is a collection of different ordered and unique elements with some exceptions like:
- It consists of only objects and nothing else.
- The objects inside Weak Set have a poor reference, which means they will be garbage collected if they do not have any reference.
- There are only three methods of Weak Set, namely add, has, and delete.
11
State the difference between the operators “==” and “===”.“==” and “===” are comparison operators. The “==” operator is used to compare values, and the “===” operator is used to compare values and types.
12
What is dataType and contentType in jQuery Ajax callscontentType is header information sent to server, that will specify a particular format. For example you are going to send JSON or XML data.
dataType tells the jQuery that, what kind of response you will receive from server. For example JSON, XML or HTML etc.
13
What is the difference between null and undefined?In JavaScript, When you declare a variable but not initialize it to any value then it's treated as undefined. Whereas null is an assignment value to any variable with no value. Type of undefined is undefined but type of null is an object. So undefined is an type whereas null is an object.
14
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.
15
What close() does in Javascript?In Javascript close() method is used to close the current window. You must write window.close() to ensure that this command is associated with a window object and not some other JavaScript object.
16
Explain “use strict”?“use strict” is a javascript directive that is introduced in Es5. The purpose of using “use strict” directive is to enforce the code is executed in strict mode. In strict mode we can’t use a variable without declaring it. “use strict” is ignored by earlier versions of Javascript.
17
In Javascript are calculations with fractional numbers guaranteed to be precise?NO, calculations with fractional numbers are not guaranteed to be precise in Javascript
18
List the comparison operators supported by Javascript?Javascript supports below comparison operators
- > Greater than
- < Less than
- <= Less than or equal to
- >= Greater than or equal to
- == Equal to
- != Not Equal to
- === Equal to with datatype check
- !== Not equal to with datatype check
19
What are the primitive data types in JavaScript?A primitive is a basic data type that’s not built out of other data types. It can only represent one single value. All primitives are built-in data types by necessity, (the compiler has to know about them,) but not all built-in data types are primitives.
In JavaScript there are 5 primitive data types are available they are undefined, null, boolean, string and number are available.Everything else in Javascript is an object.
20
Do you think Javascript has concept level scope?No. JavaScript does not have perception level scope. The variable affirmed inside the function has range inside the function.
21
What do you mean by break and continue statements?Break statement departs from the existing loop.
Continue statement continues with next declaration of the loop
22
How generic objects can be created?Generic objects can be shaped as:
var I = new object();
23
What is the use of type of operator?'Type of' is an operator which is used to revisit a string explanation of the kind of a variable.
24
Tell me some features of Javascript?Some features are:
- Lightweight & Interpreted
- Open- cross-platform
- Network-centric
- Integrated
25
What do you mean by prompt box in Javascript?A prompt box is a box which allows the user to pierce input by providing a text box. The prompt () technique displays a dialog box that prompts the caller for input. A prompt box is frequently used if you want the consumer to input a value before ingoing a page. When a prompt box pops up, the user will have to tick either “OK” or “Cancel” to carry on after entering an input value.
26
How are object properties assigned?Assigning properties to objects is done in the similar way as a value is assigned to a variable. For example, a shape object's action value is assigned as 'submit' in the following mode - Document.form.action="submit"
27
How can a specific frame be targeted, from a hyperlink, in Javascript?This can be done by counting the name of the necessary frame in the hyperlink using the 'target' quality.
<a href="https://www.e3docs.com/" target="newframe">Home</a>
28
What is the method for reading and writing a file in Javascript?This can be done by Using JavaScript additions, example for opening of a file -
fh = fopen(getScriptPath(), 0);
29
How are DOM utilized in Javascript?DOM refers for Document Object Model and is accountable for how different objects in a document interrelate with each other. DOM is necessary for developing web pages, which includes objects like paragraph, links, etc. These objects can be operated to comprise actions like add or delete. DOM is also compulsory to add extra capabilities to a web page.
30
How are Javascript and ECMA script related?ECMA Script are like rules and teaching while Javascript is a scripting language used for web expansion.
31
How can you create an array in Javascript?You can describe arrays using the array literal as follows-
var x = []; var y = [1, 2, 3, 4, 5];
32
Define Callback?A callback is a simple JavaScript function approved to some method as a fight or option. It is a function that is to be executed after another purpose has finished executing, hence the name ‘call back.
33
Name the looping structures in Javascript?Looping structures in Javascript are:
- While
- For
- Do- while loops
34
Tell me the use of Blur button?Blur function is used to eliminate the centre from the specified object.
35
What is unshift method in Javascript?Unshift technique is like push method which works at the opening of the array. This method is used to pretend one or more elements to the opening of the array
36
How can the OS of the client machine be detected?The navigator.appVersion string can be used to notice the operating system on the client machine.
37
Explain event bubbling?JavaScript permits DOM elements to be nested inside each other. In such a case, if the trainer of the child is clicked, the handler of blood relation will also work as if it were clicked too.
38
What is the role of a strict mode in JavaScript?JavaScript is ‘not very strict’ in throwing errors. Sometimes, it displays result even when there are some errors. To overcome this problem we can use JavaScript strict mode. In ‘Strict mode’ JavaScript code throws all types of errors. This reduces bugs and makes debugging easier and thus, helps developers to avoid unnecessary mistakes.
To enable strict mode, write "use strict" at the top of the script.
39
What is the difference between innerHTML and innerText?innerHTML- It interprets an HTML tag if found in a string as HTML and sets the same content in HTML format.
innerText - It interprets an HTML tag as text and sets the content of the tag as plain text.
40
What is NaN in JavaScript?NaN is a special value that denotes Not-a-Number and cannot be represented as a meaningful number. There are many ways in which NaN can happen such as dividing zero by zero, converting a non-numeric string into a number etc
We can use isNan() function to see if a value is an NaN value. The function returns true if the argument passed is not a number otherwise it returns false.
41
Describe a time you received feedback on a programming task. How did it help you become a better programmer?This is a typical open-ended question. The candidate should demonstrate they can accept, understand and act on feedback.
42
What is the difference between JavaScript and Jscript?Netscape provided the JavaScript language. Microsoft changed the name and called it JScript to avoid the trademark issue. In other words, you can say JScript is the same as JavaScript, but it is provided by Microsoft.
43
What is BOM?BOM stands for Browser Object Model. It provides interaction with the browser. The default object of the browser is the window.
44
What is the use of window object?he window object is automatically created by the browser that represents a window of a browser.
It is used to display the popup dialog box such as the alert dialog box, confirm dialog box, input dialog box, etc.
45
What is the use of history objects?The history object of the browser can be used to switch to history pages such as back and forward from the current page or another page. There are three methods of history object.
history.back()
history.forward()
history.go(number): number may be positive for forward, negative for backward.
46
How to write HTML code dynamically using JavaScript?The innerHTML property is used to write the HTML code using JavaScript dynamically. Let's see a simple example:
document.getElementById('mylocation').innerHTML="<h2>This is heading using JavaScript</h2>";
47
What is the real name of JavaScript?The original name was Mocha, a name chosen by Marc Andreessen, founder of Netscape. In September of 1995, the name was changed to LiveScript. In December 1995, after receiving a trademark license from Sun, the name JavaScript was adopted.
48
What is the difference between Local Storage and Session Storage?Local Storage will stay until it is manually cleared through settings or program.
Session Storage will leave when the browser is closed.
49
Name some of the Javascript frameworks.There are many Javascript Frameworks available today, but the most commonly used frameworks are:
- Angular
- React
- Vue
50
In how many ways a Javascript code can be involved in an HTML file?The Javascript code can be involved in 3 ways
- Inline
- Internal
- External