Technical interview questions and answers are extremely important for JavaScript Interviews because JavaScript powers most modern web applications. Companies evaluate your understanding of functions, scope, closures, events, DOM manipulation, ES6 features, promises, async/await, and real-time coding skills. JavaScript is one of the most commonly tested subjects in frontend developer interviews, full-stack roles, and placement assessments. Companies like TCS, Infosys, Wipro, Cognizant, and Accenture frequently include JavaScript questions in their technical rounds. This guide covers the most frequently asked JavaScript interview questions with detailed explanations to help freshers and job seekers prepare effectively. Learning these questions will give you confidence during coding tests, practical tasks, and web development interviews.
Frontend developers should enhance their skills by mastering CSS styling techniques and HTML structure fundamentals
1. what is the differene between java and java script?
Answer: Java Script is object based language it is used for front end validations
java is object oriented language object oriented language supports OOP's Object based not suppoted inheritence.
Show Answer
Hide Answer
2. What are JavaScript types?
Answer: Number, String, Boolean, Function, Object, Null, Undefined.
Show Answer
Hide Answer
3. How do you convert numbers between different bases in JavaScript?
Answer: Use the parseInt() function, that takes a string as the first parameter, and the base as a second parameter. So to convert hexadecimal 3F to decimal, use parseInt ("3F", 16);
Show Answer
Hide Answer
5. What is negative infinity?
Answer: Its a number in JavaScript, derived by dividing negative number by zero.
Show Answer
Hide Answer
7. What does "1"+2+4 evaluate to?
Answer: Since 1 is a string, everything is a string, so the result is 124.
Show Answer
Hide Answer
8. What looping structures are there in JavaScript?
Answer: for, while, do-while loops, but no foreach.
Show Answer
Hide Answer
9. How do you create a new object in JavaScript?
Answer: var obj = new Object(); or var obj = {};
Show Answer
Hide Answer
13. What is the main difference between Client side JavaScript and and Server side Java Script. How actually they run on both side with Example?
Answer: Clientside Javascript encompasses the core language plus extras such as the predefined objects, only relevant to running Javasript in a browser.The clientside javascript is embedded directly in the HTML pages and is interpreted by the browser completly at the run time. Serverside javascript also encompasses the core language plus extas as the predefined objects and functions only relevant to running Javasript in a server.The serverside javascripts are compiled before they are deployed.
Show Answer
Hide Answer
14. What is JavaScript?
Answer: JavaScript is a general-purpose programming language designed to let programmers of all skill levels control the behavior of software objects. The language is used most widely today in Web browsers whose software objects tend to represent a variety of HTML elements in a document and the document itself. But the language can be--and is--used with other kinds of objects in other environments. For example, Adobe Acrobat Forms uses JavaScript as its underlying scripting language to glue together obj
Show Answer
Hide Answer
15. What is JavaScript?
Answer: JavaScript is a platform-independent,event-driven, interpreted client-side scripting and programming language developed by Netscape Communications Corp. and Sun Microsystems.
Show Answer
Hide Answer
16. whats relationship between JavaScript and ECMAScript?
Answer: ECMAScript is yet another name for JavaScript (other names include LiveScript). The current JavaScript that you see supported in browsers is ECMAScript revision 3.
Show Answer
Hide Answer
17. How do you submit a form using Javascript?
Answer:
Use document.forms[0].submit();
(0 refers to the index of the form if you have more than one form in a page, then the first one has the index 0, second has index 1 and so on).
Show Answer
Hide Answer
18. How to detect the operating system on the client machine?
Answer: In order to detect the operating system on the client machine, the navigator.appVersion
string (property) should be used
Show Answer
Hide Answer
19. How do you target a specific frame from a hyperlink?
Answer: Include the name of the frame in the target attribute of the hyperlink.
>My Page
Show Answer
Hide Answer
20. Where are cookies actually stored on the hard disk?
Answer: This depends on the user's browser and OS.
In the case of Netscape with Windows OS,all the cookies are stored in a single file called
cookies.txt
c:\Program Files\Netscape\Users\username\cookies.txt
In the case of IE,each cookie is stored in a separate file namely username@website.txt.
c:\Windows\Cookies\username@Website.txt
Show Answer
Hide Answer
21. What can javascript programs do?
Answer: Generation of HTML pages on-the-fly without accessing the Web server. The user can be given control over the browser like User input validation Simple computations can be performed on the client's machine The user's browser, OS, screen size, etc. can be detected Date and Time Handling
Show Answer
Hide Answer
22. How to set a HTML document's background color?
Answer: document.bgcolor property can be set to any appropriate color.
Show Answer
Hide Answer
24. In a pop-up browser window, how do you refer to the main browser window that opened it?
Answer: Use window.opener to refer to the main window from pop-ups.
Show Answer
Hide Answer
25. What is the data type of variables of in JavaScript?
Answer: All variables are of object type in JavaScript
Show Answer
Hide Answer
26. Methods GET and POST in HTML forms - what's the difference?
Answer: GET: Parameters are passed in the querystring. Maximum amount of data that can be sent via the GET method is limited to about 2kb.
POST: Parameters are passed in the request body. There is no limit to the amount of data that can be transferred using POST. However, there are limits on the maximum amount of data that can be transferred in one name/value pair.
Show Answer
Hide Answer
27. How to write a script for "Select" lists using javascript
Answer: 1. To remove an item from a list set it to null
mySelectObject.options[3] = null;
2. To truncate a list set its length to the maximum size you desire
mySelectObject.length = 2;
3. To delete all options in a select object set the length to 0.
mySelectObject.leng
Show Answer
Hide Answer
28. Text From Your Clipboard?
Answer: It is true, text you last copied for pasting (copy & paste) can be stolen when you visit web sites using a combination of JavaScript and ASP (or PHP, or CGI) to write your possible sensitive data to a database on another server.
Show Answer
Hide Answer
29. What does the "Access is Denied" IE error mean?
Answer: The "Access Denied" error in any browser is due to the following reason.
A javascript in one window or frame is tries to access another window or frame whose document's domain is different from the document containing the script.
Show Answer
Hide Answer
30. Is a javascript script faster than an ASP script?
Answer: Yes.Since javascript is a client-side script it does require the web server's help for its
computation,so it is always faster than any server-side script like ASP,PHP,etc..
Show Answer
Hide Answer
31. Are Java and JavaScript the Same?
Answer: No.java and javascript are two different languages.
Java is a powerful object - oriented programming language like C++,C whereas Javascript is a client-side scripting language with some limitations.
Show Answer
Hide Answer
32. How to embed javascript in a web page?
Answer: javascript code can be embedded in a web page between tags
Show Answer
Hide Answer
33. What and where are the best JavaScript resources on the Web?
Answer: The Web has several FAQ areas on JavaScript. The best place to start is something called the meta-FAQ [14-Jan-2001 Editor's Note: I can't point to it anymore, it is broken!], which provides a high-level overview of the JavaScript help available on the Net. As for fact-filled FAQs, I recommend one maintained by Martin Webb and a mini-FAQ that I maintain.
For interactive help with specific problems, nothing beats the primary JavaScript Usenet newsgroup, comp.lang.javascript. Depending on my work
Show Answer
Hide Answer
34. What is the difference between a web-garden and a web-farm?
Answer: Web-garden - An IIS6.0 feature where you can configure an application pool as a web-garden and also specify the number of worker processes for that pool. It can help improve performance in some cases.
Web-farm - a general term referring to a cluster of physically separate machines, each running a web-server for scalability and performance (contrast this with web-garden which refers to multiple processes on one single physical machine).
Show Answer
Hide Answer
35. How to get the contents of an input box using Javascript?
Answer: Use the "value" property.
var myValue = window.document.getElementById("MyTextBox").value;
Show Answer
Hide Answer
36. How to determine the state of a checkbox using Javascript?
Answer: var checkedP = window.document.getElementById("myCheckBox").checked;
Show Answer
Hide Answer
37. How to set the focus in an element using Javascript?
Answer: script> function setFocus() { if(focusElement != null) { document.forms[0].elements["myelementname"].focus(); } }
Show Answer
Hide Answer
38. How to access an external javascript file that is stored externally and not embedded?
Answer: This can be achieved by using the following tag between head tags or between body tags.
How to access an external javascript file that is stored externally and not embedded? where abc.js is the external javscript file to be accessed.
Show Answer
Hide Answer
39. What is the difference between an alert box and a confirmation box?
Answer: An alert box displays only one button which is the OK button whereas the Confirm box displays two buttons namely OK and cancel.
Show Answer
Hide Answer
40. What is a prompt box?
Answer: A prompt box allows the user to enter input by providing a text box.
Show Answer
Hide Answer
41. Can javascript code be broken in different lines?
Answer: Breaking is possible within a string statement by using a backslash \ at the end but not within any other javascript statement.
that is ,
document.write("Hello \ world");
is possible but not document.write \
("hello world");
Show Answer
Hide Answer
42. What Web sites do you feel use JavaScript most effectively (i.e., best-in-class examples)? The worst?
Answer: The best sites are the ones that use JavaScript so transparently, that I'm not aware that there is any scripting on the page. The worst sites are those that try to impress me with how much scripting is on the page.
Show Answer
Hide Answer
43. How about 2+5+"8"?
Answer: Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, Its concatenation, so 78 is the result.
Show Answer
Hide Answer
44. What is the difference between SessionState and ViewState?
Answer: ViewState is specific to a page in a session. Session state refers to user specific data that can be accessed across all pages in the web application.
Show Answer
Hide Answer
45. What does the EnableViewStateMac setting in an aspx page do?
Answer: Setting EnableViewStateMac=true is a security measure that allows ASP.NET to ensure that the viewstate for a page has not been tampered with. If on Postback, the ASP.NET framework detects that there has been a change in the value of viewstate that was sent to the browser, it raises an error - Validation of viewstate MAC failed.
Use <%@ Page EnableViewStateMac="true"%> to set it to true (the default value, if this attribute is not specified is also true) in an aspx page.
Show Answer
Hide Answer
47. How to hide javascript code from old browsers that dont run it?
Answer: Use the below specified style of comments
hit me
Show Answer
Hide Answer
63. How to have the status line update when the mouse goes over a link (The support of the status line is sporadic)?
Answer: