1What 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.
2What are the data types supported by JavaScript?
The data types supported by JavaScript are:
- Undefined
- Null
- Boolean
- String
- Symbol
- Number
- Object
3What are the features of JavaScript?
Following are the features of JavaScript:
- It is a lightweight, interpreted programming language.
- It is designed for creating network-centric applications.
- It is complementary to and integrated with Java.
- It is an open and cross-platform scripting language.
4Enumerate 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.
5Is 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.
6Between 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).
7What are the advantages of JavaScript?
Following are the advantages of using JavaScript −
- Less server interaction − You can validate user input before sending the page off to the server. This saves server traffic, which means less load on your server.
- Immediate feedback to the visitors − They don’t have to wait for a page reload to see if they have forgotten to enter something.
- Increased interactivity − You can create interfaces that react when the user hovers over them with a mouse or activates them via the keyboard.
- Richer interfaces − You can use JavaScript to include such items as drag-and-drop components and sliders to give a Rich Interface to your site visitors.
8How 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
};
9What is negative infinity?
Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero.
10Is 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");
11Which company developed JavaScript?
Netscape is the software company who developed JavaScript.
12What 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.
13What 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.
14What 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.
15What is 'this' keyword in JavaScript?
'This' keyword refers to the object from where it was called.
16Explain the working of timers in JavaScript? Also elucidate the drawbacks of using the timer, if any?
Timers are used to execute a piece of code at a set time or also to repeat the code in a given interval of time. This is done by using the functions setTimeout, setInterval and clearInterval.
The setTimeout(function, delay) function is used to start a timer that calls a particular function after the mentioned delay. The setInterval(function, delay) function is used to repeatedly execute the given function in the mentioned delay and only halts when cancelled. The clearInterval(id) function instructs the timer to stop.
Timers are operated within a single thread, and thus events might queue up, waiting to be executed.
17Which symbol is used for comments in Javascript?
// for Single line comments and
/* Multi
Line
Comment
*/
18What 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.
19What is === operator?
=== is called as strict equality operator which returns true when the two operands are having the same value without any type conversion.
20Does JavaScript support automatic type conversion?
Yes JavaScript does support automatic type conversion, it is the common way of type conversion used by JavaScript developers
21How can the style/class of an element be changed?
It can be done in the following way:
document.getElementById("myText").style.fontSize = "20?;
or
document.getElementById("myText").className = "anyclass";
22How can you create an Array in JavaScript?
You can define arrays using the array literal as follows-
var x = [];
var y = [1, 2, 3, 4, 5];
23Explain 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
24What are all the looping structures in JavaScript?
Following are looping structures in Javascript:
25What 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";
26What 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.
27What is the function of delete operator?
The delete keyword is used to delete the property as well as its value.
Example :
var student= {age:20, batch:"ABC"};
delete student.age;
28What are all the types of Pop up boxes available in JavaScript?
29What 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.
30What is the data type of variables in JavaScript?
All variables in the JavaScript are object data types.
31What 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 m a "good" boy"
document.write "I m a \"good\" boy"
32What 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.
33Whether JavaScript has concept level scope?
No. JavaScript does not have concept level scope. The variable declared inside the function has scope inside the function.
34Mention what is the disadvantage of using innerHTML in JavaScript?
If you use innerHTML in JavaScript the disadvantage is
35What is break and continue statements?
Break statement exits from the current loop.
Continue statement continues with next statement of the loop.
36What 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.
37What is the use of type of operator?
'Typeof' is an operator which is used to return a string description of the type of a variable.
38Which keyword is used to print the text in the screen?
document.write("Welcome") is used to print the text – Welcome in the screen.
39What is the use of blur function?
Blur function is used to remove the focus from the specified object.
40How 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.
41What are the different types of errors in JavaScript?
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.
42What is the use of Push method in JavaScript?
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
43What is the difference between JavaScript and Jscript?
Both are almost similar. JavaScript is developed by Netscape and Jscript was developed by Microsoft .
44Explain the for-in loop?
The for-in loop is used to loop through the properties of an object.
The syntax for the for-in loop is -
for (variable name in object){
statement or block to execute
}
In each repetition, one property from the object is associated to the variable name, and the loop is continued till all the properties of the object are depleted.
45Define 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.
46What boolean operators can be used in JavaScript?
The 'And' Operator (&&), 'Or' Operator (||) and the 'Not' Operator (!) can be used in JavaScript.
*Operators are without the parenthesis.
47What 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);
48How 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.
49Explain 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.
50What 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.
51What are Screen objects?
Screen objects are used to read the information from the client's screen. The properties of screen objects are -
- AvailHeight: 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
52What is Callback?
A callback is a plain JavaScript function passed to some method as an argument or option. It is a function that is to be executed after another function has finished executing, hence the name ‘call back‘. In JavaScript, functions are objects. Because of this, functions can take functions as arguments, and can be returned by other functions.
53What 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.
54How to read a cookie using JavaScript?
Reading a cookie is just as simple as writing one, because the value of the document.cookie object is the cookie. So you can use this string whenever you want to access the cookie.
- The document.cookie string will keep a list of name = value pairs separated by semicolons, where name is the name of a cookie and value is its string value.
- You can use strings’ split() function to break the string into key and values.
55How to delete a cookie using JavaScript?
If you want to delete a cookie so that subsequent attempts to read the cookie 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.
56What is the difference between Attributes and Property?
Attributes- provide more details on an element like id, type, value etc.
Property- is the value assigned to the property like type=”text”, value=’Name’ etc.
57List out the different ways an HTML element can be accessed in a JavaScript code.
Here are the list of ways an HTML element can be accessed in a Javascript code:
(i) getElementById(‘idname’): Gets an element by its ID name
(ii) getElementsByClass(‘classname’): Gets all the elements that have the given classname.
(iii) getElementsByTagName(‘tagname’): Gets all the elements that have the given tag name.
(iv) querySelector(): This function takes css style selector and returns the first selected element.
58In how many ways a JavaScript code can be involved in an HTML file?
There are 3 different ways in which a JavaScript code can be involved in an HTML file:
An inline function is a JavaScript function, which is assigned to a variable created at runtime. You can differentiate between Inline Functions and Anonymous since an inline function is assigned to a variable and can be easily reused. When you need a JavaScript for a function, you can either have the script integrated in the page you are working on, or you can have it placed in a separate file that you call, when needed. This is the difference between an internal script and an external script.
59What are the ways to define a variable in JavaScript?
The three possible ways of defining a variable in JavaScript are:
- Var – The JavaScript variables statement is used to declare a variable and, optionally, we can initialize the value of that variable. Example: var a =10; Variable declarations are processed before the execution of the code.
- Const – The idea of const functions is not allow them to modify the object on which they are called. When a function is declared as const, it can be called on any type of object.
- Let – It is a signal that the variable may be reassigned, such as a counter in a loop, or a value swap in an algorithm. It also signals that the variable will be used only in the block it’s defined in.
60What is the difference between innerHTML & innerText?
innerHTML – It will process an HTML tag if found in a string
innerText – It will not process an HTML tag if found in a string