(1) Enumerate the differences between Java and JavaScript?
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 and it is said to be unstructured programming.
(2) What is the use of is NaN function?
isNan function returns true if the argument is not a number otherwise it is false.
(3) What is negative infinity?
Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero.
(4) Is it possible to break JavaScript Code into several lines?
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.
Var x=1, y=2, z=x+y;
The above code is perfectly fine, though not advisable as it hampers debugging.
(5) What are undeclared and undefined variables?
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.
(6) What are global variables? How are these variable declared and what are the problems associated with using them?
Global variables are those that are available throughout the length of the code, that is, these have no scope. The var keyword is used to declare a local variable or object. If the var keyword is omitted, a global variable is declared.
Example:
// Declare a global globalVariable = “Test”;
The problems that are faced by using global variables are the clash of variable names of local and global scope. Also, it is difficult to debug and test the code that relies on global variables.
(7) What is a prompt box?
A prompt box is a box which allows the user to enter input by providing a text box. Label and box will be provided to enter the text or number.
(8) What is the difference between ViewState and SessionState?
‘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.
(9) Does JavaScript support automatic type conversion?
Yes JavaScript does support automatic type conversion; it is the common way of type conversion used by JavaScript developers.
(10) Explain how to read and write a file using JavaScript?
There are two ways to read and write a file using JavaScript
=> Using JavaScript extensions
=> Using a web page and Active X objects
(11) What is called Variable typing in Javascript?
Variable typing is used to assign a number to a variable and the same variable can be assigned to a string.
Example:-
i=10;
i=”string”
This is called variable typing.
(12) How can you convert the string of any base to integer in JavaScript?
The parseInt() function is used to convert numbers between different bases. parseInt() takes the string to be converted as its first parameter, and the second parameter is the base of the given string.
In order to convert 4F (of base 16) to integer, the code used will be –
parseInt(“4F”,16);
(13)What would be the result of 3+2+”7″?
Since 3 and 2 are integers, they will be added numerically. And since 7 is a string, its concatenation will be done. So the result would be 57.
(14) Explain how to detect the operating system on the client machine?
In order to detect the operating system on the client machine, the navigator.appVersion string (property) should be used.
(15) What do mean by NULL in Javascript?
The NULL value is used to represent no value or no object. It implies no object or null string, no valid boolean value, no number and no array object.
(16) What is the function of delete operator?
The functionality of delete operator is used to delete all variables and objects in a program but it cannot delete variables declared with VAR keyword.
(17) What are all the types of Pop up boxes available in JavaScript?
· Alert
· Confirm and
· Prompt
(18) What is the use of Void(0)?
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.
(19) How can a page be forced to load another page in JavaScript?
The following code has to be inserted to achieve the desired effect:
<script language="JavaScript" type="text/javascript" >
<!-- location.href="http://newhost/newpath/newfile.html"; //--></script>
(20) What is the difference between an alert box and a confirmation box?
An alert box displays only one button which is the OK button.
But a Confirmation box displays two buttons namely OK and cancel.
(21) What are escape characters?
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 am “good” boy”
(22) What are JavaScript Cookies?
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.
(23) Explain what is pop()method in JavaScript?
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.
Example:
Var cloths= [“Shirt”,”Pant”,”TShirt”];
cloths.pop();
//Now cloth becomes Shirt,Pant
(24) Whether JavaScript has concept level scope?
No. JavaScript does not have concept level scope. The variable declared inside the function has scope inside the function.
(25) Mention what is the disadvantage of using innerHTML in JavaScript?
Content is replaced everywhere.
We cannot use like “appending to innerHTML”.
Even if you use +=like “innerHTML = innerHTML + ‘html’” still the old content is replaced by html.
The entire innerHTML content is re-parsed and build into elements, therefore its much slower
The innerHTML does not provide validation and therefore we can potentially insert valid and broken HTML in the document and break it.
(26) What is break and continue statements?
Break statement exits from the current loop.
Continue statement continues with next statement of the loop.
(27) What are the two basic groups of dataypes in JavaScript?
They are as –Primitive, Reference types.
Primitive types are number and Boolean data types. Reference types are more complex types like strings and dates.
(28) How generic objects can be created?
Generic objects can be created as:
Var I=NEW OBJECT();
(29) Which keywords are used to handle exceptions?
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
}
(30) How will you get the Checkbox status whether it is checked or not?
var status = document.getElementById('checkbox1').checked;
alert(status);
will return true or false.
(31) Describe the properties of an anonymous function in JavaScript?
A function that is declared without any named identifier is known as an anonymous function. In general, an anonymous function is inaccessible after its declaration.
Anonymous function declaration –
var anon = function() {
alert('I am anonymous');
};
anon();
(32) What is the difference between .call() and .apply()?
The function .call() and .apply() are very similar in their usage except a little difference. .call() is used when the number of the function’s arguments are known to the programmer, as they have to be mentioned as arguments in the call statement. On the other hand, .apply() is used when the number is not known. The function .apply() expects the argument to be an array.
The basic difference between .call() and .apply() is in the way arguments are passed to the function. Their usage can be illustrated by the given example.
var someObject = {
myProperty : 'Foo',
myMethod : function(prefix, postfix) {
alert(prefix + this.myProperty + postfix);
}
};
someObject.myMethod('<', '>'); // alerts '<Foo>'
var someOtherObject = {
myProperty : 'Bar'
};
someObject.myMethod.call(someOtherObject, '<', '>'); // alerts '<Bar>'
someObject.myMethod.apply(someOtherObject, ['<', '>']); // alerts '<Bar>'
(33) How are DOM utilized in JavaScript?
DOM stands for Document Object Model and is responsible for how various objects in a document interact with each other. DOM is required for developing web pages, which includes objects like paragraph, links, etc. These objects can be operated to include actions like add or delete. DOM is also required to add extra capabilities to a web page. On top of that, the use of API gives an advantage over other existing models.
(34) Why it is not advised to use innerHTML in JavaScript?
innerHTML content is refreshed every time and thus is slower. There is no scope for validation in innerHTML and, therefore, it is easier to insert rouge code in the document and, thus, make the web page unstable.
(35) How are JavaScript and ECMA Script related?
ECMA Script are like rules and guideline while Javascript is a scripting language used for web development.
(36)What is namespacing in JavaScript and how is it used?
Namespacing is used for grouping the desired functions, variables etc. under a unique name. It is a name that has been attached to the desired functions, objects and properties. This improves modularity in the coding and enables code reuse.
(37) How can JavaScript codes be hidden from old browsers that don’t support JavaScript?
For hiding JavaScript codes from old browsers:
Add “<!–” without the quotes in the code just after the <script> tag.
Add “//–>” without the quotes in the code just before the <script> tag.
(38) Explain the unshift() method ?
This method is functional at the starting of the array, unlike the push(). It adds the desired number of elements to the top of an array. For example –
var name = [ "john" ];
name.unshift( "charlie" );
name.unshift( "joseph", "Jane" );
console.log(name);
The output is:- [" joseph "," Jane ", " charlie ", " john "]
(39) Define unescape() and escape() functions?
The escape () function is responsible for coding a string so as to make the transfer of the information from one computer to the other, across a network.
For Example:
<script>
document.write(escape(“Hello? How are you!”));
</script>
Output: Hello%3F%20How%20are%20you%21
The unescape() function is very important as it decodes the coded string.
For example:
<script>
document.write(unescape(“Hello%3F%20How%20are%20you%21”));
</script>
Output: Hello? How are you!
(40) Between JavaScript and an ASP script, which is faster?
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).
(41) What is the use of blur function?
Blur function is used to remove the focus from the specified object.
(42) How to find operating system in the client machine using JavaScript?
The ‘Navigator.appversion’ is used to find the name of the operating system in the client machine.
(43) What is the ‘Strict’ mode in JavaScript and how can it be enabled?
Strict Mode adds certain compulsions to JavaScript. Under the strict mode, JavaScript shows errors for a piece of codes, which did not show an error before, but might be problematic and potentially unsafe. Strict mode also solves some mistakes that hamper the JavaScript engines to work efficiently.
Strict mode can be enabled by adding the string literal “use strict” above the file. This can be illustrated by the given example:
function myfunction()
{
“use strict";
var v = “This is a strict mode function";
}
(44) How can the OS of the client machine be detected?
The navigator.appVersion string can be used to detect the operating system on the client machine.
(45) Explain window.onload and onDocumentReady?
The onload function is not run until all the information on the page is loaded. This leads to a substantial delay before any code is executed.
onDocumentReady loads the code just after the DOM is loaded. This allows early manipulation of the code.
(46) Define event bubbling?
JavaScript allows DOM elements to be nested inside each other. In such a case, if the handler of the child is clicked, the handler of parent will also work as if it were clicked too.
(47) How can a particular frame be targeted, from a hyperlink, in JavaScript?
This can be done by including the name of the required frame in the hyperlink using the ‘target’ attribute.
<a href=”newpage.htm” target=”newframe”>>New Page</a>
(48) Write the point of difference between web-garden and a web-farm?
Both web-garden and web-farm are web hosting systems. The only difference is that web-garden is a setup that includes many processors in a single server while web-farm is a larger setup that uses more than one server.
(49) What is the method for reading and writing a file in JavaScript?
This can be done by Using JavaScript extensions (runs from JavaScript Editor), example for opening of a file – fh = fopen(getScriptPath(), 0);
(50) How are event handlers utilized in JavaScript?
Events are the actions that result from activities, such as clicking a link or filling a form, by the user. An event handler is required to manage proper execution of all these events. Event handlers are an extra attribute of the object. This attribute includes event’s name and the action taken if the event takes place.
(51) Explain the role of deferred scripts in JavaScript?
By default, the parsing of the HTML code, during page loading, is paused until the script has not stopped executing. It means, if the server is slow or the script is particularly heavy, then the webpage is displayed with a delay. While using Deferred, scripts delays execution of the script till the time HTML parser is running. This reduces the loading time of web pages and they get displayed faster.
(52) What are the various functional components in JavaScript?
The different functional components in JavaScript are-
First-class functions: Functions in JavaScript are utilized as first class objects. This usually means that these functions can be passed as arguments to other functions, returned as values from other functions, assigned to variables or can also be stored in data structures.
Nested functions: The functions, which are defined inside other functions, are called Nested functions. They are called ‘everytime’ the main function is invoked.
(53) What are Screen objects?
Screen objects are used to read the information from the client’s screen. The properties of screen objects are –
· AvalHeight: Gives the height of client’s screen.
· AvailWidth: Gives the width of client’s screen.
· ColorDepth: Gives the bit depth of images on the client’s screen.
· Height: Gives the total height of the client’s screen, including the taskbar.
· Width: Gives the total width of the client’s screen, including the taskbar.
(54) What are the decodeURI() and encodeURI()?
EncodeURl() is used to convert URL into their hex coding. And DecodeURI() is used to convert the encoded URL back to normal.
<script>
var uri="my test.asp?name=ståle&car=saab";
document.write(encodeURI(uri)+ "<br>");
document.write(decodeURI(uri));
</script>
Output –
my%20test.asp?name=st%C3%A5le&car=saab
my test.asp?name=ståle&car=saab
No comments:
Post a Comment