Java Script Interview Questions And Answers
Question: 1. What Is Javascript?
Answer:
JavaScript is a trendy-motive programming language designed to allow programmers of all skill tiers manage the conduct of software items. The language is used maximum extensively today in Web browsers whose software program objects have a tendency to represent a variety of HTML factors in a file and the document itself. But the language can be–and is–used with different types of gadgets in different environments. For example, Adobe Acrobat Forms makes use of JavaScript as its underlying scripting language to glue together items which might be specific to the paperwork generated by Adobe Acrobat. Therefore, it’s miles critical to distinguish JavaScript, the language, from the items it could communicate with in any precise surroundings. When used for Web files, the scripts cross directly within the HTML documents and are downloaded to the browser with the rest of the HTML tags and content material.
OR
JavaScript is a platform-unbiased,event-pushed, interpreted customer-aspect scripting and programming language evolved by Netscape Communications Corp. And Sun Microsystems.
Question: 2. How To Read And Write A File Using Javascript?
Answer:
I/O operations like analyzing or writing a document is not feasible with patron-facet javascript. However , this could be executed by way of coding a Java applet that reads files for the script.
Adv Java Interview Questions
Question: three. What Are Javascript Types?
Answer:
Number, String, Boolean, Function, Object, Null, Undefined.
Question: 4. 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 bottom as a 2d parameter. So to convert hexadecimal 3F to decimal, use parseInt (“3F”, 16);
Java Script Tutorial
Question: five. What Can Javascript Programs Do?
Answer:
Generation of HTML pages on-the-fly without accessing the Web server. The user may be given manage over the browser like User input validation Simple computations may be finished at the purchaser’s gadget The user’s browser, OS, display length, and so on. May be detected Date and Time Handling.
Core Java Interview Questions
Question: 6. What Is The Data Type Of Variables Of In Javascript?
Answer:
All variables are of item kind in JavaScript.
Question: 7. Is A Javascript Faster Than An Asp Script?
Answer:
Yes.Since javascript is a patron-aspect script it does require the web server’s assist for its computation,so it is continually quicker than any server-side script like ASP,PHP,etc..
Adv Java Tutorial Java-Springs Interview Questions
Question: eight. Are Java And Javascript The Same?
Answer:
No.Java and javascript are two extraordinary languages.
Java is a powerful item – oriented programming language like C++,C while Javascript is a client-side scripting language with a few barriers.
Question: nine. How To Embed Javascript In A Web Page?
Answer:
javascript code may be embedded in a web page between tags
Java Servlets Interview Questions
Question: 10. How Is Javascript Different From Java?
Answer:
JavaScript became evolved by Brendan Eich of Netscape; Java changed into developed at Sun Microsystems. While the 2 languages share a few commonplace syntax, they were advanced independently of each different and for special audiences. Java is a full-fledged programming language tailor-made for community computing; it includes loads of its own objects, together with objects for creating user interfaces that appear in Java applets (in Web browsers) or standalone Java applications. In evaluation, JavaScript is predicated on anything environment it’s running in for the person interface, together with a Web record’s shape factors.
JavaScript changed into to begin with called LiveScript at Netscape while it changed into beneath improvement. A licensing deal between Netscape and Sun on the final minute allow Netscape plug the “Java” call into the call of its scripting language. Programmers use absolutely different gear for Java and JavaScript. It is also no longer unusual for a programmer of 1 language to be blind to the other. The languages do not depend on every other and are supposed for exclusive functions. In a few methods, the “Java” call on JavaScript has burdened the sector’s understanding of the differences between the 2. On the alternative hand, JavaScript is lots simpler to learn than Java and might provide a gentle introduction for beginners who need to graduate to Java and the styles of packages you can expand with it.
Core Java Tutorial
Question: eleven. What’s Relationship Between Javascript And Ecmascript?
Answer:
ECMAScript is yet some other name for JavaScript (different names encompass LiveScript). The contemporary JavaScript which you see supported in browsers is ECMAScript revision three.
EJB(Enterprise JavaBeans) Interview Questions
Question: 12. How Do You Submit A Form Using Javascript?
Answer:
Use report.Paperwork[0].Post();
(zero refers to the index of the shape – when you have multiple form in a page, then the primary one has the index 0, 2nd has index 1 and so forth).
Adv Java Interview Questions
Question: thirteen. How To Detect The Operating System On The Client Machine?
Answer:
In order to hit upon the operating device at the patron gadget, the navigator.AppVersion string (belongings) have to be used.
Java-Springs Tutorial
Question: 14. How Can Javascript Make A Web Site Easier To Use? That Is, Are There Certain Javascript Techniques That Make It Easier For People To Use A Web Site?
Answer:
JavaScript’s greatest potential gift to a Web web site is that scripts can make the page greater straight away interactive, that is, interactive without having to put up every little component to the server for a server application to re-render the web page and send it lower back to the patron. For instance, consider a top-level navigation panel that has, say, six number one photograph map hyperlinks into subsections of the Web site. With simplest a bit bit of scripting, each map area may be advised to pop up a more precise list of hyperlinks to the contents inside a subsection each time the user rolls the cursor atop a map area. With the assist of that popup listing of links, the consumer with a scriptable browser can bypass one intermediate menu web page. The consumer without a scriptable browser (or who has disabled JavaScript) will ought to drill down through a more conventional and time-eating course to the preferred content.
Question: 15. How To Create Arrays In Javascript?
Answer:
We can claim an array like this
var scripts = new Array();
We can add elements to this array like this
scripts[0] = “PHP”;
scripts[1] = “ASP”;
scripts[2] = “JavaScript”;
scripts[3] = “HTML”;
Now our array scrips has 4 elements inside it and we can print or get admission to them via the usage of their index quantity. Note that index wide variety starts offevolved from 0. To get the 1/3 element of the array we have to use the index number 2 . Here is the way to get the third element of an array.
File.Write(scripts[2]);
We can also create an array like this
var no_array = new Array(21, 22, 23, 24, 25);
JavaServer Faces (JSF) Interview Questions
Question: 16. How Do You Target A Specific Frame From A Hyperlink?
Answer:
Include the call of the frame in the target characteristic of the hyperlink. >My Page
Java Servlets Tutorial
Question: 17. What Is A Fixed-width Table And Its Advantages?
Answer:
Fixed width tables are rendered with the aid of the browser based at the widths of the columns inside the first row, ensuing in a quicker show in case of large tables. Use the CSS style table-layout:constant to specify a fixed width table.
If the desk is not unique to be of fixed width, the browser has to attend until all statistics is downloaded and then infer the nice width for each of the columns. This procedure may be very slow for massive tables.
Java Swing Interview Questions
Question: 18. Example Of Using Regular Expressions For Syntax Checking In Javascript
Answer:
var re = new RegExp(“^(&[A-Za-z_0-9]1,=[A-Za-z_0-9]1,)*$”);
var textual content = myWidget.Fee;
var OK = re.Test(text);
if( ! OK )
alert(“The more parameters need some work.Rn Should be some thing like: “&a=1&c=4″”);
Core Java Interview Questions
Question: 19. How To Add Buttons In Javascript?
Answer:
The most basic and historical use of buttons are the “put up” and “clear”, which appear barely before the Pleistocene duration. Notice whilst the “GO!” button is pressed it submits itself to itself and appends the call in the URL.
Another beneficial method is to set the “kind” to “button” and use the “onclick” occasion.
EJB(Enterprise JavaBeans) Tutorial
Question: 20. How To Set A Html Document’s Background Color?
Answer:
record.Bgcolor assets can be set to any appropriate color.
Java Interview Questions
Question: 21. How Can Javascript Be Used To Personalize Or Tailor A Web Site To Fit Individual Users?
Answer:
JavaScript allows a Web web page to carry out “if-then” kinds of choices based totally on browser model, operating system, consumer enter, and, in extra recent browsers, information about the display screen size wherein the browser is going for walks. While a server CGI software could make some of those equal kinds of choices, now not all people has get right of entry to to or the know-how to create CGI programs. For example, an experienced CGI programmer can study facts approximately the browser whenever a request for a page is made; thus a server so ready might serve up one page for Navigator users and a distinct page for Internet Explorer customers. Beyond browser and operating gadget version, a CGI program cannot understand greater about the environment. But a JavaScript-more desirable web page can train the browser to render simplest positive content material primarily based at the browser, running device, or even the display screen length.
Scripting may even cross similarly if the page writer dreams. For instance, the author can also encompass a preference display that shall we the consumer decide the desired history and textual content colour mixture. A script can store this facts at the purchaser in a well-regulated neighborhood document called a cookie. The next time the user involves the site, scripts in its pages look to the cookie information and render the web page within the shade aggregate decided on previously. The server is none the wiser, nor does it ought to save any visitor-specific facts.
Question: 22. Are You Concerned That Older Browsers Don’t Support Javascript And Thus Exclude A Set Of Web Users? Individual Users?
Answer:
Fragmentation of the set up base of browsers will most effective worsen. By definition, it can by no means enhance except truely everybody on this planet threw away their old browsers and upgraded to the cutting-edge gee-whiz versions. But even then, there are plenty of discrepancies between the scriptability of the state-of-the-art Netscape Navigator and Microsoft Internet Explorer.
The situation makes scripting a undertaking, mainly for learners who might not be privy to the restrictions of earlier browsers. A lot of attempt in my books and ancillary cloth is going in the direction of helping scripters recognise what functions work wherein browsers and the way to either workaround obstacles in in advance browsers or raise the compatibility common denominator.
Designing scripts for a Web site calls for making a few difficult selections about if, when, and a way to implement the blessings scripting gives a page for your target audience. For public Web websites, I recommend the usage of scripting in an additive manner: let sufficient content stand on its very own, but let scriptable browser users receive an greater experience, preferably with the identical HTML document.
JavaServer Faces (JSF) Tutorial
Question: 23. What Does Isnan Function Do?
Answer:
Return true if the argument isn’t always a range of.
Javascript Objects Interview Questions
Question: 24. What Is Negative Infinity?
Answer:
It’s a number of in JavaScript, derived by using dividing negative quantity by means of zero.
Java-Springs Interview Questions
Question: 25. In A Pop-up Browser Window, How Do You Refer To The Main Browser Window That Opened It?
Answer:
Use window.Opener to consult the main window from pop-ups.
Java Swing Tutorial
Question: 26. Methods Get And Post In Html Forms – What’s The Difference?.
Answer:
GET: Parameters are passed within the querystring. Maximum amount of records that may be despatched via the GET technique is constrained to about 2kb.
POST: Parameters are surpassed in the request frame. There is not any restrict to the amount of statistics that may be transferred the use of POST. However, there are limits at the maximum amount of information that can be transferred in a single call/value pair.
Javascript Advanced Interview Questions
Question: 27. How To Write A Script For “pick” Lists Using Javascript
Answer:
1. To put off an item from a listing set it to null
mySelectObject.Options[3] = null;
2. To truncate a listing set its length to the maximum size you preference
mySelectObject.Duration = 2;
3. To delete all alternatives in a pick out object set the period to zero.
MySelectObject.Leng
Java Servlets Interview Questions
Question: 28. Text From Your Clipboard?
Answer:
It is genuine, textual content you ultimate copied for pasting (replica & paste) can be stolen while you visit web web sites using a combination of JavaScript and ASP (or PHP, or CGI) to write your viable sensitive records to a database on any other server.
Java Tutorial
Question: 29. What Does The “access Is Denied” Ie Error Mean?
Answer:
The “Access Denied” blunders in any browser is due to the subsequent cause.
A javascript in one window or body is tries to get entry to another window or body whose file’s domain is different from the file containing the script.
JavaMail API Interview Questions
Question: 30. What Are The Problems Associated With Using Javascript, And Are There Javascript Techniques That You Discourage?
Answer:
Browser version incompatibility is the most important hassle. It requires understanding how each scriptable browser version implements its item version. You see, the incompatibility rarely has to do with the core JavaScript language (even though there had been enhancements to the language over the years); the majority of incompatibility troubles must do with the object models that every browser version implements. For example, scripters who started out with Navigator three carried out the photograph rollover as it looked cool. But they had been dismayed to find out that the photograph item wasn’t scriptable in Internet Explorer three or Navigator 2. While there are clean workarounds to make this feature work on newer browsers without worrying older ones, it became a painful getting to know revel in for plenty.
The 2nd largest can of worms is scripting connections among more than one windows. A lot of scripters want to have little home windows pop up with navigation bars or some such gizmos. But the item fashions, especially inside the older browser variations, don’t make it easy to work with these home windows the minute you put a user in front of them–users who can manually near home windows or alternate their stacking order. More lately, a glitch in a few uninstall routines for Windows ninety five programs can disturb essential components of the machine Registry that Internet Explorer four requires for coping with a couple of home windows. A scripter can’t work round this hassle, as it’s not feasible to stumble on the hassle in a user’s system. I tend to avoid more than one windows that interact with every different. I suppose a whole lot of inexperienced Web surfers can also get burdened by4 Evaluate To?
Answer:
Since 1 is a string, the whole lot is a string, so the result is 124.
Java 8 Interview Questions
Question: 33. What Are The Ways To Emit Client-side Javascript From Server-side Code In Asp.Net?
Answer:
The Page item in ASP.NET has strategies that permit emitting of purchaser-side JavaScript:
RegisterClientScriptBlock and RegisterStartupScript.
Example usage:
Page.RegisterClientScriptBlock(“ScriptKey”, ““);
Page.RegisterStartupScript(“ScriptKey”, ““);
ScriptKey is used to suppress the same JavaScript from being emitted extra than as soon as. Multiple calls to RegisterClientScriptBlock or RegisterStartupScript with the same value of ScriptKey emit the script best once, on the first name.
EJB(Enterprise JavaBeans) Interview Questions
Question: 34. What Is The Difference Between Registerclientscriptblock And Registerstartupscript?
Answer:
RegisterClientScriptBlock emits the JavaScript simply after the hole tag. RegisterStartupScript emits the JavaScript at the lowest of the ASP.NET web page just earlier than the ultimate tag.
Question: 35. What Is The Difference Between A Web-garden And A Web-farm?
Answer:
Web-garden – An IIS6.0 feature wherein you may configure an software pool as an internet-lawn and additionally specify the variety of employee processes for that pool. It can assist improve overall performance in some cases.
Web-farm – a preferred time period regarding a cluster of physically separate machines, each strolling a web-server for scalability and overall performance (evaluation this with web-lawn which refers to multiple methods on one single physical device).
Question: 36. How To Get The Contents Of An Input Box Using Javascript?
Answer:
Use the “price” assets.
Var myValue = window.Document.GetElementById(“MyTextBox”).Cost;
JavaServer Faces (JSF) Interview Questions
Question: 37. How To Determine The State Of A Checkbox Using Javascript?
Answer:
var checkedP = window.Document.GetElementById(“myCheckBox”).Checked;
Question: 38. How To Set The Focus In An Element Using Javascript?
Answer:
Question: 39. How To Access An External Javascript File That Is Stored Externally And Not Embedded?
Answer:
This may be performed via the use of the subsequent tag between head tags or among frame tags.
How to get entry to an external javascript report that is stored externally and not embedded? Wherein abc.Js is the outside javscript file to be accessed.
Question: forty. What Is The Difference Between An Alert Box And A Confirmation Box?
Answer:
An alert container presentations most effective one button that’s the OK button while the Confirm field displays two buttons namely OK and cancel.
Java Swing Interview Questions
Question: 41. What Is A Prompt Box?
Answer:
A set off field permits the person to enter input by offering a text field.
Question: 42. Can Javascript Code Be Broken In Different Lines?
Answer:
Breaking is possible inside a string announcement by means of using a backslash at the stop however not within another javascript statement.
This is ,
report.Write(“Hello international”);
is feasible but not document.Write
(“hi there international”);
Java Interview Questions
Question: forty three. Taking A Developer’s Perspective, Do You Think That That Javascript Is Easy To Learn And Use?
Answer:
One of the motives JavaScript has the word “script” in it’s far that as a programming language, the vocabulary of the middle language is compact as compared to full-fledged programming languages. If you already application in Java or C, you clearly ought to unlearn some concepts that had been overwhelmed into you. For instance, JavaScript is a loosely typed language, which means that a variable does not care if it is keeping a string, a number, or a connection with an item; the same variable can even exchange what form of facts it holds while a script runs.
The different part of JavaScript implementation in browsers that makes it less complicated to examine is that most of the items you script are pre-described for the author, and that they largely constitute physical matters you could see on a page: a textual content box, an picture, and so forth. It’s less difficult to mention, “OK, these are the matters I’m operating with and I’ll use scripting to cause them to do such and such,” rather of getting to dream up the person interface, conceive of and code gadgets, and manage the interaction between items and customers. With scripting, you generally tend to jot down a _lot_ much less code.
Question: forty four. How About 2+5+”8″?
Answer:
Since 2 and 5 are integers, that is wide variety mathematics, in view that eight is a string, it’s concatenation, so seventy eight is the end result.
Question: forty five. What Is The Difference Between Sessionstate And Viewstate?
Answer:
ViewState is particular to a page in a session. Session country refers to consumer particular statistics that can be accessed throughout all pages in the web application.
Question: forty six. What Does The Enableviewstatemac Setting In An Aspx Page Do?
Answer:
Setting EnableViewStateMac=authentic is a safety measure that lets in ASP.NET to make sure 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 within the cost of viewstate that changed into sent to the browser, it raises an blunders – Validation of viewstate MAC failed.
Use <%@ Page EnableViewStateMac="true"%> to set it to true (the default cost, if this attribute isn’t precise is also authentic) in an aspx page.
Question: forty seven. How To Accessing Elements Using Javascript?
Answer:
To do some thing exciting with HTML elements, we should first be capable of uniquely perceive which detail we need. In the instance
We can use the “getElementById” technique (that’s typically favored)
file.GetElementById(“useless”).Fashion.Coloration = “red”;
or we will use the older hierarchical navigation method,
report.Forms[0].Mybutton.Fashion.Colour = “blue”;
Notice that this makes use of the “name” characteristic of the element to discover it.
# Example of Accessing Elements in a DOM.
Question: 48. What Looping Structures Are There In Javascript?
Answer:
for, even as, do-whilst loops, but no foreach.
Question: forty nine. To Put A “close Window” Link On A Page ?
Answer:
Question: 50. How To Hide Javascript Code From Old Browsers That Dont Run It?
Answer:
Use the under targeted fashion of remarks
Question: sixty one. What Does Undefined Value Mean In Javascript?
Answer:
Undefined cost way the variable used in the code doesnt exist or isn't always assigned any fee or the property doesnt exist.
Question: sixty two. What Is The Difference Between Undefined Value And Null Value?
Answer:
(i)Undefined value cannot be explicitly stated this is there may be no keyword referred to as undefined whereas null value has keyword referred to as null
(ii)typeof undefined variable or assets returns undefined while typeof null cost returns item
Question: 63. What Is Variable Typing In Javascript?
Answer:
It is perfectly criminal to assign a number to a variable and then assign a string to the same variable as follows
example
i = 10;
i = "string";
This is called variable typing
Question: 64. Does Javascript Have The Concept Level Scope?
Answer:
No.Javascript does not have block degree scope,all of the variables declared interior a feature possess the identical degree of scope unlike c,c++,java.
Question: 65. What Are Undefined And Undeclared Variables?
Answer:
Undeclared variables are those that aren't declared inside the software (do now not exist in any respect),trying to study their values gives runtime blunders.But if undeclared variables are assigned then implicit declaration is carried out .
Undefined variables are those who are not assigned any value but are declared within the software.Trying to read such variables gives special value known as undefined value.
Question: 66. What Is === Operator ?
Answer:
==== is strict equality operator ,it returns true best whilst the 2 operands are having the same price with none kind conversion.
Question: sixty seven. How To Find The Selected Radio Button Immediately Using The 'this' Variable?
Answer:
onchange="favAnimal(this)">Kangaroo
onchange="favAnimal(this)">Opossum
onchange="favAnimal(this)">Tasmanian Tiger
Question: sixty eight. How To Find Radio Button Selection When A Form Is Submitted?
Answer:
