JavaScript

Description: A test on JavaScript programming.
Number of Questions: 25
Created by:
Tags: HTML Java JavaScript Web Development Client Side Scripting Programming HTML WebPage WebSite BBA / BBS / BCA Java/Oracle /C/C++
Attempted 0/25 Correct 0 Score 0

Which of the following type of box is used to get input from the user?

  1. inputbox

  2. alert

  3. confirm

  4. prompt

  5. dialog


Correct Option: D
Explanation:

The prompt box is used to get input from the user. It has an inbuilt text box where the user can type a value. After typing the data, the user must click on either 'OK' or cancel to continue. The value entered by the user is stored in a variable and the further action can be taken.

Which of the following is the correct syntax to access an element of the form object?

  1. document.forms.element

  2. document.forms[0].elements[0]

  3. document[0].forms.element

  4. document.forms.elements[0]

  5. document.forms[0].element


Correct Option: B
Explanation:

if a web document contains a form element it can be referred in JavaScript using the syntax -document.forms[0]

If the Web document contains two form elements the first form is referred to as document.forms[0] and the second document.forms[1]. Therefore we can access first form element using document.forms[0].elements[0], the second element can be accessed as document.forms[0].elements[1] and so on.

Which of the following event occurs when an image does not load properly?

  1. onabort

  2. onerror

  3. onunload

  4. onblur

  5. onimageunload


Correct Option: B
Explanation:

The onerror event triggers when an image does not load properly. It can be written as onerror="error handling code"

Which of the following is NOT a valid property of the 'plugin' object?

  1. name

  2. filename

  3. description

  4. mimetypes

  5. path


Correct Option: E
Explanation:

Path is not a valid property of the 'plugin' object.

What will the output of the statement - Math.ceil(5.3)

  1. 5

  2. 6

  3. 4

  4. 0

  5. 5.3


Correct Option: B
Explanation:

The ceil method rounds a number upward to it's nearest integer. The result of ceil(5.3) will be 6

Which property of the 'navigator' object is used to detect the name of the client browser?

  1. appCodeName

  2. appBrowserName

  3. appVersion

  4. appName

  5. userAgent


Correct Option: D
Explanation:

The appName property returns the name of the browser for example Microsoft Internet Explorer or FireFox.

Which of the following is NOT a valid cookie field?

  1. expires

  2. domain

  3. path

  4. policy

  5. secure


Correct Option: D
Explanation:

'policy' is not a valid cookie field.

Which property of the 'Location' object returns the complete URL?

  1. href

  2. hash

  3. hostname

  4. pathname

  5. host


Correct Option: A
Explanation:

The href property of the 'Location' object returns the entire path or URL of the current page.

Which of the following function returns the position of a specified character in a String?

  1. charAt

  2. indexOf

  3. valueOf

  4. substring

  5. match


Correct Option: B
Explanation:

The indexOf() returns the index or position of a character or a string in the given string. The indexOf() returns -1 is the searched character is not found. For example in the following codevar str="aliensbrain.com"; var n=str.indexOf("l");The value of 'n' will be '2' since it is the 2nd character in the string starting from 0.

Which of the following is NOT a feature of JavaScript?

  1. Less server interaction

  2. We can handle events in JavaScripts

  3. JavaScript supports multithreading.

  4. It makes a web page dynamic

  5. Supports drag and drop.


Correct Option: C
Explanation:

Multithreading is the process of running multiple threads simultaneously. JavaScript doesn't have any multithreading or multiprocess capabilities.

With reference to the RegExp object which meta character used to find a NON WORD CHARACTER?

  1. w

  2. v

  3. W

  4. n

  5. D


Correct Option: C
Explanation:

The W meta character is used to find a non-word character.'W' searches any character that is not a word character from the basic Latin alphabet. Equivalent to [^A-Za-z0-9_].

Which operator is used to find out if the specified property is in the specified object?

  1. in

  2. comma

  3. new

  4. this

  5. typeof


Correct Option: A
Explanation:

The 'in' operator returns true if the specified property is in the specified object. The following syntax can be used for the 'in' operator propertyname in objectname

What will be the output of the above code?

var arr = new Array();
arr[0] = "Element 1";
arr[1] = "Element 2";
arr[2] = "Element 3";
arr[3] = "Element 4";
document.write(arr[0, 1, 2, 3]);
  1. Error

  2. Element 1

  3. Element 4

  4. Element 1, Element 2, Element 3, Element 4

  5. No output (blank screen)


Correct Option: C
Explanation:

The result will be Element 4. The other elements will not be printed. To print all the values of the array a loop can be used.

If we want to write a statement that processes irrespective of whether the program has an exception or not, it should be written inside the ___ block.

  1. try

  2. else

  3. catch

  4. if

  5. finally


Correct Option: E
Explanation:

The finally block contains the code that we want to run irrespective of whether the try block contains an exception or not. If the try block has an exception the control will move from the try block to the catch block and then to the finally block. If there is no exception the control will move directly from the try block to the finally block.

Which of the following functions is used to determine if the argument is a number?

  1. parseInt

  2. isNan

  3. isFinite

  4. eval

  5. isDigit


Correct Option: B
Explanation:

The isNaN function evaluates an argument to determine if it is NaN (not a number). The syntax of isNaN is -  isNan(value_to_check);

Which of the following properties returns the values of the pixels of the length of the width and height of the viewer's screen?

  1. screen.width and screen.height

  2. Resolution.width and Resolution.height

  3. screen.pixels.width and screen.pixels.height

  4. ViewerScreen.width and ViewerScreen.height

  5. None of the above.


Correct Option: A
Explanation:

The width and height property of the screen object returns the total width and height of the screen.

Which of the following event occurs when an object loses its focus.

  1. onblur

  2. onfocuslost

  3. onunload

  4. onreset

  5. onchange


Correct Option: A
Explanation:

The onblur event occurs when a control on the form loses it focus. This event is mainly used for data validation purpose when the user tries to leave a control after filling the data.

What will be the output of the above code?

fun3();
function fun1(i) {
  function fun2(j) { return i * j; }
  return fun2;
}
function fun3() {
  r = fun1(5)(5);
  alert(r);
}
  1. 5

  2. 15

  3. 10

  4. 25

  5. Compilation Error


Correct Option: D
Explanation:

Functions are another type of variable in JavaScript. Creating a function within another function changes the scope of the function in the same way it would change the scope of a variable.The functions defined within another function won't be accessible outside the function unless they have been attached to an object that is accessible outside the function. In the above code, we are calling the function named 'fun3()' , which in turn is calling another function named 'fun1()' with two arguments (5) and (5). The fun1() will copy the value of the first 5 to i and the second value will be copied to j. The result of fun2() will be sent to 'fun1()'. fun1() will return the result (25) to fun3(). The result will be copied to the variable 'r' and printed using an alert box.

Which of the following is NOT a JavaScript reserved word?

  1. continue

  2. label

  3. with

  4. export

  5. bool


Correct Option: E
Explanation:

'bool' is not a reserved JavaScript keyword. 

Which of the following statements is false regarding the 'substring' function having the above syntax?

string.substring(index1,index2);

  1. If index1 equals index1, substring returns an empty string.

  2. If any of the argument is less than 0 it is considered as 0.

  3. If index2 is not specified, substring extracts characters till the end of the string.

  4. If either argument is greater than the length of the string, it is considered as the same value as stringName.length.

  5. It is compulsory to pass at least one argument while calling the substring() function.


Correct Option: E
Explanation:

It is not compulsory to pass an argument while calling the substring() function. If no arguments are specified, the actual string will be printed as it is. In the following example, the output will be 'welcome'

var str=welcome;document.write(str.substring());

Which of the following statements is FALSE regarding the null data type?

  1. The null data type has only one value.

  2. The typeOf operator shows null as boolean values.

  3. null is not same as 0

  4. null is a keyword

  5. Value of a variable can be set as null.


Correct Option: B
Explanation:

The typeof operator in JavaScript identifies null values as being of type Object, not of type boolean.

Which of the following tasks CAN NOT be performed by JavaScript?

  1. Detecting client browser information.

  2. Validating user input.

  3. Handling date and time.

  4. Mathematical calculations on client system.

  5. Access files on the client system.


Correct Option: E
Explanation:

JavaScript can not directly access files on the user's system the only exception is the access to the browser's cookie files. 

Which of the following is NOT a restriction while using the "strict option" in JavaScript?

  1. Variables must be declared

  2. Parameter name can not be duplicated

  3. eval can not be used as an identifier.

  4. with statement

  5. The word string can not be used as an identifer


Correct Option: E
Explanation:

String can be used as an identifier even if the strict option is specified.

What will be the output of the above code snippet?

var str=This is a sample string;
var output=str.split(,);
document.write(output);

  1. Compilation Error

  2. This,is,a,sample,string

  3. This,is,a,sample,string,

  4. ,This,is,a,sample,string,

  5. T,h,i,s,i,s,a,s,a,m,p,l,e,s,t,r,i,n,g


Correct Option: B
Explanation:

The split() method is used to split a string into an array of substrings, and returns the new array. In the above code, the spaces of the string will be converted to commas (,)

Which of the following statements is FALSE regarding InnerHTML?

  1. The content of a webpage can be changed dynamically using InnerHTML.

  2. The id of an element can be referred by using getElement() method.

  3. InnerHTML is not a part of DOM.

  4. It was introduced by Microsoft.

  5. It is valid for both block and inline elements.


Correct Option: B
Explanation:

Each element that we want to modify dynamically must be assigned a unique id. The InnerHTML property is used along with the getElementById() method to refer to a particular element by using its Id.

- Hide questions