JavaScript Question
- Why so JavaScript and Java have similar name?
A. JavaScript is a stripped-down version of Java
B. JavaScript's syntax is loosely based on Java's
C. They both originated on the island of Java
D. None of the above - 2. When a user views a page containing a JavaScript program, which machine actually executes the script?
A. The User's machine running a Web browser
B. The Web server
C. A central machine deep within Netscape's corporate offices
D. None of the above - 3. ______ JavaScript is also called client-side JavaScript.
A. Microsoft
B. Navigator
C. LiveWire
D. Native - 4. __________ JavaScript is also called server-side JavaScript.
A. Microsoft
B. Navigator
C. LiveWire
D. Native - 5. What are variables used for in JavaScript Programs?
A. Storing numbers, dates, or other values
B. Varying randomly
C. Causing high-school algebra flashbacks
D. None of the above - 6. _____ JavaScript statements embedded in an HTML page can respond to user events such as mouse-clicks, form input, and page navigation.
A. Client-side
B. Server-side
C. Local
D. Native - 7. What should appear at the very end of your JavaScript?
The <script LANGUAGE="JavaScript">tag
A. The </script>
B. The <script>
C. The END statement
D. None of the above - Which of the following can't be done with client-side JavaScript?
A. Validating a form
B. Sending a form's contents by email
C. Storing the form's contents to a database file on the server
D. None of the above - 9. Which of the following are capabilities of functions in JavaScript?
A. Return a value
B. Accept parameters and Return a value
C. Accept parameters
D. None of the above - 10. Which of the following is not a valid JavaScript variable name?
A. 2names
B. _first_and_last_names
C. FirstAndLast
D. None of the above - 11. ______ tag is an extension to HTML that can enclose any number of JavaScript statements.
A. <SCRIPT>
B. <BODY>
C. <HEAD>
D. <TITLE> - 12. How does JavaScript store dates in a date object?
A. The number of milliseconds since January 1st, 1970
B. The number of days since January 1st, 1900
C. The number of seconds since Netscape's public stock offering.
D. None of the above - 13. Which of the following attribute can hold the JavaScript version?
A. LANGUAGE
B. SCRIPT
C. VERSION
D. None of the above - 14. What is the correct JavaScript syntax to write "Hello World"?
A. System.out.println("Hello World")
B. println ("Hello World")
C. document.write("Hello World")
D. response.write("Hello World") - 15. Which of the following way can be used to indicate the LANGUAGE attribute?
A. <LANGUAGE="JavaScriptVersion">
B. <SCRIPT LANGUAGE="JavaScriptVersion">
C. <SCRIPT LANGUAGE="JavaScriptVersion"> JavaScript statements…</SCRIPT>
D. <SCRIPT LANGUAGE="JavaScriptVersion"!> JavaScript statements…</SCRIPT> - 16. Inside which HTML element do we put the JavaScript?
A. <js>
B. <scripting>
C. <script>
D. <javascript> - 17. What is the correct syntax for referring to an external script called " abc.js"?
A. <script href=" abc.js">
B. <script name=" abc.js">
C. <script src=" abc.js">
D. None of the above - 18. Which types of image maps can be used with JavaScript?
A. Server-side image maps
B. Client-side image maps
C. Server-side image maps and Client-side image maps
D. None of the above - 19. Which of the following navigator object properties is the same in both Netscape and IE?
A. navigator.appCodeName
B. navigator.appName
C. navigator.appVersion
D. None of the above - 20. Which is the correct way to write a JavaScript array?
A. var txt = new Array(1:"tim",2:"kim",3:"jim")
B. var txt = new Array:1=("tim")2=("kim")3=("jim")
C. var txt = new Array("tim","kim","jim")
D. var txt = new Array="tim","kim","jim" - Which of the following navigator object properties is the same in both Netscape and IE?
A. navigator.appCodeName
B. navigator.appName
C. navigator.appVersion
D. None of the above - Which is the correct way to write a JavaScript array?
A. var txt = new Array(1:"tim",2:"kim",3:"jim")
B. var txt = new Array:1=("tim")2=("kim")3=("jim")
C. var txt = new Array("tim","kim","jim")
D. var txt = new Array="tim","kim","jim" - 21. What does the <noscript> tag do?
A. Enclose text to be displayed by non-JavaScript browsers.
B. Prevents scripts on the page from executing.
C. Describes certain low-budget movies.
D. None of the above - 22. If para1 is the DOM object for a paragraph, what is the correct syntax to change the text within the paragraph?
A. "New Text"?
B. para1.value="New Text";
C. para1.firstChild.nodeValue= "New Text";
D. para1.nodeValue="New Text";
A. Semicolon, colon
B. Semicolon, Ampersand
C. Ampersand, colon
D. Ampersand, semicolon
24. Which of the following best describes JavaScript?
A. a low-level programming language.
B. a scripting language precompiled in the browser.
C. a compiled scripting language.
D. an object-oriented scripting language.
25. Choose the server-side JavaScript object?
A. FileUpLoad
B. Function
C. File
D. Date
26. Choose the client-side JavaScript object?
A. Database
B. Cursor
C. Client
D. FileUpLoad
27. Which of the following is not considered a JavaScript operator?
A. new
B. this
C. delete
D. typeof
28. ______method evaluates a string of JavaScript code in the context of the specified object.
A. Eval
B. ParseInt
C. ParseFloat
D. Efloat
29. Which of the following event fires when the form element loses the focus: <button>, <input>, <label>, <select>, <textarea>?
A. onfocus
B. onblur
C. onclick
D. ondblclick
30. The syntax of Eval is ________________
A. [objectName.]eval(numeriC.
B. [objectName.]eval(string)
C. [EvalName.]eval(string)
D. [EvalName.]eval(numeriC.
31. JavaScript is interpreted by _________
A. Client
B. Server
C. Object
D. None of the above
32. Using _______ statement is how you test for a specific condition.
A. Select
B. If
C. Switch
D. For
33. Which of the following is the structure of an if statement?
A. if (conditional expression is true) thenexecute this codeend if
B. if (conditional expression is true)execute this codeend if
C. if (conditional expression is true) {then execute this code>->}
D. if (conditional expression is true) then {execute this code}
34. How to create a Date object in JavaScript?
A. dateObjectName = new Date([parameters])
B. dateObjectName.new Date([parameters])
C. dateObjectName := new Date([parameters])
D. dateObjectName Date([parameters])
35. The _______ method of an Array object adds and/or removes elements from an array.
A. Reverse
B. Shift
C. Slice
D. Splice
36. To set up the window to capture all Click events, we use which of the following statement?
A. window.captureEvents(Event.CLICK);
B. window.handleEvents (Event.CLICK);
C. window.routeEvents(Event.CLICK );
D. window.raiseEvents(Event.CLICK );
37. Which tag(s) can handle mouse events in Netscape?
A. <IMG>
B. <A>
C. <BR>
D. None of the above
38. ____________ is the tainted property of a window object.
A. Pathname
B. Protocol
C. Defaultstatus
D. Host
39. To enable data tainting, the end user sets the _________ environment variable.
A. ENABLE_TAINT
B. MS_ENABLE_TAINT
C. NS_ENABLE_TAINT
D. ENABLE_TAINT_NS
40. In JavaScript, _________ is an object of the target language data type that encloses an object of the source language.
A. a wrapper
B. a link
C. a cursor
D. a form
41. When a JavaScript object is sent to Java, the runtime engine creates a Java wrapper of type ___________
A. ScriptObject
B. JSObject
C. JavaObject
D. Jobject
42. _______ class provides an interface for invoking JavaScript methods and examining JavaScript properties.
A. ScriptObject
B. JSObject
C. JavaObject
D. Jobject
43. _________ is a wrapped Java array, accessed from within JavaScript code.
A. JavaArray
B. JavaClass
C. JavaObject
D. JavaPackage
44. A ________ object is a reference to one of the classes in a Java package, such as netscape.javascript .
A. JavaArray
B. JavaClass
C. JavaObject
D. JavaPackage
45. The JavaScript exception is available to the Java code as an instance of __________
A. netscape.javascript.JSObject
B. netscape.javascript.JSException
C. netscape.plugin.JSException
D. None of the above
46. To automatically open the console when a JavaScript error occurs which of the following is added to prefs.js?
A. user_pref(" javascript.console.open_on_error", false);
B. user_pref("javascript.console.open_error ", true);
C. user_pref("javascript.console.open_error ", false);
D. user_pref("javascript.console.open_on_error", true);
47. To open a dialog box each time an error occurs, which of the following is added to prefs.js?
A. user_pref("javascript.classic.error_alerts", true);
B. user_pref("javascript.classic.error_alerts ", false);
C. user_pref("javascript.console.open_on_error ", true);
D. user_pref("javascript.console.open_on_error ", false);
48. The syntax of a blur method in a button object is ______________
A. Blur()
B. Blur(contrast)
C. Blur(value)
D. Blur(depth)
49. The syntax of capture events method for document object is ______________
A. captureEvents()
B. captureEvents(args eventType)
C. captureEvents(eventType)
D. captureEvents(eventVal)
50. The syntax of close method for document object is ______________
A. Close(doC.
B. Close(object)
C. Close(val)
D. Close()
51. <script type="text/javascript">
x=4+"4";
document.write(x);
</script>
Output------?
A. 44
B. 8
C. 4
D. Error output
52. Is it possible to nest functions in JavaScript?
A. True
B. False
53. <script>
document.write(navigator.appCodeName);
</script>
A. get code name of the browser of a visitor
B. set code name of the browser of a visitor
C. None of the above
54. Scripting language are
A. High Level Programming language
B. Assembly Level programming language
C. Machine level programming language
55. Which best explains getSelection()?
A. Returns the VALUE of a selected OPTION.
B. Returns document.URL of the window in focus.
C. Returns the value of cursor-selected text
D. Returns the VALUE of a checked radio input.
56. Choose the client-side JavaScript object:
A. Database
B. Cursor
C. Client
D. FileUpLoad
57. What is mean by "this" keyword in javascript?
A. It refers current object
B. It referes previous object
C. It is variable which contains value
D. None of the above
58. In JavaScript, Window.prompt() method return true or false value ?
A. False
B. True
59. <script language="javascript">
function x()
{
document.write(2+5+"8");
}
</script>
A. 258
B. Error
C. 7
D. 78
60. <script type="text/javascript">
var s = "9123456 or 80000?";
var pattern = /d{4}/;
var output = s.match(pattern);
document.write(output);
</script>
A. 9123
B. 91234
C. 80000
D. None of the above
Answers
1-B 2-A 3-B 4-C 5-a 6-a 7-A 8-C 9-C 10-A
11-A 12-A 13-A 14-C 15-C 16-C 17-C 18-B 19-A 20-C
21-A 22-B 23-D 24-D 25-C 26-D 27-B 28-A 29-B 30-B
31-A 32-B 33-C 34-A 35-D 36-A 37-B 38-C 39-C 40-A
41-B 42-B 43-A 44-B 45-B 46-D 47-A 48-A 49-C 50-D
51-A 52-A 53-A 54-A 55-C 56-D 57-A 58-A 59-D 60-A
1. JavaScript Code can be called by using ___________
a) RMI
b) Triggering Event
c) Preprocessor
d) Function/Method
View Answer
Answer: d
Explanation: JavaScript code can be called by making a function call to the element on which JavaScript has to be run. There are many other methods like onclick, onload and onsubmit etc.
2. The type of a variable that is volatile is _______________
a) Volatile variable
b) Mutable variable
c) Immutable variable
d) Dynamic variable
View Answer
Answer: b
Explanation: The variables whose values can be changed are called mutable variable types. In JavaScript, only objects and arrays are mutable, not primitive values.
3. A hexadecimal literal begins with __________
a) 00
b) 0x
c) 0X
d) Both 0x and 0X
View Answer
Answer: d
Explanation: Generally, X or x denotes hexadecimal values. So, any integer literal that begins with 0X or 0x denotes a hexadecimal number.
4. The generalised syntax for a real number representation is __________
a) [digits][.digits][(E|e)[(+|-)]digits].
b) [digits][+digits][(E|e)[(+|-)]digits].
c) [digits][(E|e)[(+|-)]digits].
d) [.digits][digits][(E|e)[(+|-)]digits].
View Answer
Answer: a
Explanation: Floating-point literals may also be represented using exponential notation: a real number followed by the letter e (or E), followed by an optional plus or minus sign, followed by an integer exponent. This notation represents the real number multiplied by 10 to the power of the exponent.
5. JavaScript _________ when there is an indefinite or an infinite value during an arithmetic computation.
a) Prints an exception error
b) Prints an overflow error
c) Displays “Infinity”
d) Prints the value as such
View Answer
Answer: c
Explanation: When the result of a numeric operation is larger than the largest represent able number (overflow), JavaScript prints the value as Infinity. Similarly, when a negative value becomes larger than the largest represent able negative number, the result is negative infinity. The infinite values behave as you would expect: adding, subtracting, multiplying, or dividing them by anything results in an infinite value (possibly with the sign reversed).
6. Which of the following is not considered as an error in JavaScript?
a) Syntax error
b) Missing of semicolons
c) Division by zero
d) Missing of Bracket
View Answer
Answer: c
Explanation: Division by zero is not an error in JavaScript: it simply returns infinity or negative infinity. There is one exception, however: zero divided by zero does not have a well defined value, and the result of this operation is the special not-a-number value, printed as NaN.
7. The escape sequence ‘\f’ stands for _________
a) Floating numbers
b) Representation of functions that returns a value
c) \f is not present in JavaScript
d) Form feed
View Answer
Answer: d
Explanation: \f is the JavaScript escape sequence that stands for Form feed (\u000C). It skips to the start of the next page. (Applies mostly to terminals where the output device is a printer rather than a VDU).
advertisement
8. The snippet that has to be used to check if “a” is not equal to “null” is _________
a) if(a!=null)
b) if (!a)
c) if(a!null)
d) if(a!==null)
View Answer
Answer: d
Explanation: A strict comparison (e.g., ===) is only true if the operands are of the same type and the contents match. The more commonly-used abstract comparison (e.g. ==) converts the operands to the same type before making the comparison. The not-equal operator !== compares 0 to null and evaluates to either true or false.
9. The statement a===b refers to _________
a) Both a and b are equal in value, type and reference address
b) Both a and b are equal in value
c) Both a and b are equal in value and type
d) There is no such statement
View Answer
Answer: c
Explanation: :”===” operator is known as strict comparison operator. A strict comparison (===) is only true if the operands are of the same type and the contents match.
10. Assume that we have to convert “false” that is a non-string to string. The command that we use is (without invoking the “new” operator)
a) false.toString()
b) String(false)
c) String newvariable=”false”
d) Both false.toString() and String(false)
View Answer
Answer: d
Explanation: The three approaches for converting to string are: value.toString(),”” + value and String(value). A non-string can be converted in two ways without using a new operator false.toString () and String(false).
1. What will be the output of the following Javascript code?
var string1 = ”123”;
var intvalue = 123;
alert( string1 + intvalue );
a) 123246
b) 246
c) 123123
d) Exception
View Answer
Answer: c
Explanation: In JavaScript the alert function does the type casting and converts the integer value to string. After that it concatenates both the strings and shows the result as a concatenated string. Thus 123123 would be correct.
2. A function definition expression can be called as __________
a) Function prototype
b) Function literal
c) Function calling
d) Function declaration
View Answer
Answer: b
Explanation: A function definition expression is a “function literal” in the same way that an object initializer is an “object literal.” A Function definition expression typically consists of the keyword function followed by a comma-separated list of zero or more identifiers (the parameter names) in parentheses and a block of JavaScript code (the function body) in curly braces.
3. The property of a primary expression is ____________
a) stand-alone expressions
b) basic expressions containing all necessary functions
c) contains variable references alone
d) contains only keywords
View Answer
Answer: a
Explanation: The simplest expressions, known as primary expressions, are those that stand alone — they do not include any simpler expressions. Primary expressions in JavaScript are constant or literal values, certain language keywords, and variable references.
4. Consider the following statements.
var text = "testing: 1, 2, 3"; // Sample text
var pattern = /\d+/g // Matches all instances of one or more digits
In order to check if the pattern matches with the string “text”, the statement is
a) text==pattern
b) text.equals(pattern)
c) text.test(pattern)
d) pattern.test(text)
View Answer
Answer: d
Explanation: The given pattern is applied on the text given in the parenthesis.
5. The expression of calling ( or executing ) a function or method in JavaScript is called ________
a) Primary expression
b) Functional expression
c) Invocation expression
d) Property Access Expression
View Answer
Answer: c
Explanation: An invocation expression is JavaScript’s syntax for calling (or executing) a function or method) It starts with a function expression that identifies the function to be called.
6. What kind of an expression is “new Point(2,3)”?
a) Primary Expression
b) Object Creation Expression
c) Invocation Expression
d) Constructor Calling Expression
View Answer
Answer: b
Explanation: An object creation expression creates a new object and invokes a function (called a constructor) to initialize the properties of that object. Object creation expressions are like invocation expressions except that they are prefixed with the keyword new.
7. Which of the operator is used to test if a particular property exists or not?
a) in
b) exist
c) within
d) exists
View Answer
Answer: a
Explanation: The operator “in” tests whether a particular property exists or not. In operator is usually added in looping statements to traverse the array or the object.
8. Among the following, which one is a ternary operator?
a) +
b) :
c) –
d) ?:
View Answer
Answer: d
Explanation: JavaScript supports one ternary operator, the conditional operator ?:, which combines three expressions into a single expression. If else case can be replaced by the conditional operator
advertisement
9. “An expression that can legally appear on the left side of an assignment expression.” is a well known explanation for variables, properties of objects, and elements of arrays. They are called
a) Properties
b) Prototypes
c) Lvalue
d) Definition
View Answer
Answer: c
Explanation: lvalue is a historical term that means “an expression that can legally appear on the left side of an assignment expression.” In JavaScript, variables, properties of objects, and elements of arrays are lvalues.
10. The below code snippet is equivalent to __________
x = ~-y;
w = x = y = z;
q = a?b:c?d:e?f:g;
a)
x = ~(-y); w = (x = (y = z));
q = a?b:(c?d:(e?f:g));
b)
x = a?b:(c?d:(e?f:g));
q = ~(-y); w = (x = (y = z));
c)
x = (x = (y = z));w = ~(-y);
q = a?b:(c?d:(e?f:g));
d)
x = ~(-y); w = (x = (y = z));
q = (c?d:(e?f:g));
View Answer
Answer: a
Explanation: Brackets have higher precedence than any other operator. The placement of brackets results in the same result as without putting any bracket
1. JavaScript is a _______________ language.
a) Object-Oriented
b) High-level
c) Assembly-language
d) Object-Based
View Answer
Answer: d
Explanation: JavaScript is not a full-blown OOP (Object-Oriented Programming) language, such as Java or PHP, but it is an object-based language. The criteria for object orientation are the classic threesome of polymorphism, encapsulation and inheritance and JavaScript doesn’t pass this.
2. What would be the most appropriate output for the following code snippet?
var a=5 , b=1
var obj = { a : 10 }
with(obj)
{
alert(b)
}
a) 10
b) Error
c) 1
d) 5
View Answer
Answer: c
Explanation: Firstly the interpreter checks obj for property b.But it doesn’t find any property b so it takes the value from outside the object within the code snippet.
3. A conditional expression is also called a _______________
a) Alternative to if-else
b) Immediate if
c) If-then-else statement
d) None of the mentioned
View Answer
Answer: b
Explanation: A conditional expression can evaluate to either True or False based on the evaluation of the condition. If the condition is true then the value following the operator is taken that’s why it is called immediate if.
4. Which is a more efficient code snippet?
Code 1 :
for(var num=10;num>=1;num--)
{
document.writeln(num);
}
Code 2 :
var num=10;
while(num>=1)
{
document.writeln(num);
num++;
}
a) Code 1
b) Code 2
c) Both Code 1 and Code 2
d) Cannot Compare
View Answer
Answer: a
Explanation: Code 1 would be more efficient. Infact second code will go into runtime error as the value of num will never reach less than or equal to one.
5. What is block statement in JavaScript?
a) conditional block
b) block that contains a single statement
c) both conditional block and single statement
d) block that combines multiple statements into a single compound statement
View Answer
Answer: d
Explanation: A block statement groups zero or more statements. In languages other than JavaScript, it is known as a compound statement. A statement block is a block that combines more than one statements into a single compound statement for ease.
6. When an empty statement is encountered, a JavaScript interpreter __________
a) Ignores the statement
b) Prompts to complete the statement
c) Throws an error
d) Shows a warning
View Answer
Answer: a
Explanation: The JavaScript interpreter takes no action when it executes an empty statement. The empty statement is occasionally useful when you want to create a loop that has an empty body.
advertisement
7. The “var” and “function” are __________
a) Keywords
b) Declaration statements
c) Data types
d) Prototypes
View Answer
Answer: b
Explanation: The var and function are declaration statements—they declare or define variables and functions. These statements define identifiers (variable and function names) that can be used elsewhere in your program and assign values to those identifiers.
8. Consider the following statements
switch(expression)
{
statements
}
In the above switch syntax, the expression is compared with the case labels using which of the following operator(s)?
a) ==
b) equals
c) equal
d) ===
View Answer
Answer: d
Explanation: A strict comparison (e.g., ===) is only true if the operands are of the same type and the contents match. When a switch executes, it computes the value of expression and then looks for a case label whose expression evaluates to the same value (where sameness is determined by the === operator).
9. What happens in the following javascript code snippet?
var count = 0;
while (count < 10)
{
console.log(count);
count++;
}
a) The values of count are logged or stored in a particular location or storage
b) The value of count from 0 to 9 is displayed in the console
c) An error is displayed
d) An exception is thrown
View Answer
Answer: b
Explanation: Console.log is a predefined function in JavaScript which takes the value as an argument of its function.console.log prints this value in the argument in the console at the time of execution of the code.
10. The enumeration order becomes implementation dependent and non-interoperable if:
a) If the object inherits enumerable properties
b) The object does not have the properties present in the integer array indices
c) The delete keyword is never used
d) Object.defineProperty() is not used
View Answer
Answer: a
Explanation: In computer programming, an enumerated type (also called enumeration or enum) is a data type consisting of a set of named values called elements, members or enumerators of the type. The enumerator names are usually identifiers that behave as constants in the language