Test
answers for JavaScript 2015
Elance • IT & Programming
1. Which of the following is a JavaScript comment?
Answers:
• \\ comment
• //
comment
• # comment
• <!-- comment -->
• -- comment
2. var foo =
'Global'; function fun() { log( foo
); var foo = 'Local'; log( foo ); } fun(); What the output of the above to log()?
Answers:
• Global Local
• undefined
Local
• Global Global
3. console.log( typeof [1,2] ) will print out:
Answers:
• string
• array
• undefined
• number
• object
4. JavaScript is ...
Answers:
• subjective
• object
based
• objective
• evil
5. Every object is linked to a _________ object from
which it can inherit properties.
Answers:
• argument
• prototype
• sibling
• parent
6. What is the value of x? var x = typeof NaN;
Answers:
•
"number"
• "double"
• "object"
• "integer"
• "nan"
7. What will be the value of result? function foo(bar) { return bar ? bar == foo : foo(foo); } var result = foo();
Answers:
• Function won't work due
to incorrect syntax
• Value will be null
• Function will end up in
infinite loop
• false
• true
8. What values will the output function be called
with, in the following code: var foo;
var bar = { name:
"baz", email: "fiz@example.com", sendmail: function() { } }; for (foo in bar) { output(foo); }
Answers:
•
"name", "email", "sendmail"
• "baz",
"fiz@example.com", null
• "name",
"email"
• "baz",
"fiz@example.com", undefined
• Type Error
9. Consider: var x = ['a', 'b', 'c']; Which line of code will remove the first
element of the array, resulting in x being equal to ['b', 'c']?
Answers:
• x.splice(0);
•
x.splice(0, 1);
• x.pop();
• x.unshift(0);
10. What is the value of x? var z = [typeof z, typeof y][0]; var x =
typeof typeof z;
Answers:
• "undefined"
• "array"
• "object"
•
"string"
11. var x = {}; var foo = function () { this.hello = "Hi"; return this; }; x.bar = foo; What is the value of the following code:
x.bar().bar().hello;
Answers:
• TypeError: Object -- has
no method 'bar'
•
"Hi"
• "function () {
this.hello = "Hi"; return this; }"
• undefined
• TypeError: Cannot call
method 'bar' of undefined
12. Which of the following assigned values of x will
cause (x == x) to return false?
Answers:
• 0/0
• NaN
• Number("foo")
• All of
the answers
13. What would this code print out? if (new Boolean(false)) console.log("True"); else console.log("False");
Answers:
• True
• False
14. Which two values are logged by the following
code? var x = 5; (function () { console.log(x); var x = 10; console.log(x); }());
Answers:
• 10 10
• 5 10
• undefined
10
• nothing. Throws
ReferenceError: x is not defined
15. Infinity * null will return :
Answers:
• null
• Infinity
• NaN
16. Assuming alert displays a string of its
argument: var a = 10; function
example(){ alert(a); var a
= 5; } example(); What will be shown if the preceding code is
executed?
Answers:
• 5
• null
• 10
• undefined
17. What is the result? "" ? "a" : "b"
Answers:
• ""
•
"b"
• "a"
• Error: "" is
not a boolean
18. What is the value of x? var x = typeof null;
Answers:
• "null"
• null
•
"object"
• undefined
19. The length property of an Array object is
always:
Answers:
• equal to the number of
properties in that object
• equal to the highest
index of that object
• equal to
the highest index of that object + 1
20. var data = [1, 2, 3, 4, 5, 6]; data.shift();
What does data look like?
Answers:
• [2, 3, 4,
5, 6]
• [1, 2, 3, 4, 5]
• [undefined, 1, 2, 3, 4,
5]
• [undefined, 2, 3, 4, 5,
6]
• [6, 1, 2, 3, 4, 5]
21. Which fact is true about the keyword
"default"?
Answers:
• It does not exist in
JavaScript
• It
catches any case clauses not caught by case statements within a switch
statement
• It sets up one variable
to check against multiple values
• It branches program logic
based on the value of a condition
22. Which String prototype method is capable of
removing a character from a string?
Answers:
• destroy()
• delete()
• remove()
• replace()
23. What is the value of x after the following
statement? var x = 1 == '1';
Answers:
• true
• false
• '1'
• 1
• undefined
24. What is the result of the following code
snippet? var small = 'BIG'; var BIG =
'small'; console.log(/small/.test(BIG)); console.log(/BIG/.test(small));
Answers:
• false false
• true false
• false true
• true true
25. What is the result of the following statement:
typeof "x";
Answers:
•
"string"
• "[object
String]"
• "undefined"
• "character"
• Throws error
"ReferenceError: x is not defined"
26. Is there a value type for individual string
characters?
Answers:
• Yes, accessing a
character offset from a (non-empty) string will yield a value of type
"char".
• No, there
is only type "string" for characters.
27. Given a variable named stringVar with a string
value, what does the following do?
stringVar.toUpperCase();
Answers:
• Evaluate any string
expression in stringVar
• Alters stringVar, changes
all letters to uppercase
• Return a
copy of stringVar with all letters in uppercase
• Return the number of
characters in the stringVar variable
28. Which is an example of (only) an object literal
in Javascript?
Answers:
• var obj =
{ prop1: 'property 1', prop2: 'property 2' };
• var obj = [
"property 1", "property 2" ]
• var obj = new Object() {
this.prop1 = 'property 1'; this.prop2 = 'property 2'; }
• var obj = [ {prop1:
'property 1', prop2: 'property2'} ]
29. The loop isn't working. What's the problem?
<code> var foos = ['a', 'b', 'c' , 'd', 'e']; var bars = ['x', 'y', 'z'];
for (var i = 0; i < foos.length; i++) {
var foo = foos[i]; for (var i =
0; i < bars.length; i++) { var bar = bars[i]; /* some code using `bar` */ } } </code>
Answers:
• There is no bug. The loop
will run correctly.
• The inner
loop resets the outer for-loop, leaving it a fixed position each time, causing
an infinite loop (hint: no block scope).
• Uncaught SyntaxError.
• The outer-loop finishes
after the first iteration due to a "bug" that unfortunately is part
of the ECMAScript specification.
30. Functions in javascript are always ..
Answers:
• objects
• in the global scope
• operators
• loops
31. How do you read the first character in a string?
Answers:
• data.substr(0);
• data.slice(1)
• data.charAt(1);
• data.substring(1);
•
data.charAt(0);
32. Which of the following have special meanings
within the language syntax?
Answers:
• Literals
• Reserved
words
• Identifiers
• Variables
33. What is the result? 0 == ""
Answers:
• false
• true
• Error: type mismatch
34. Primitive types are passed by :
Answers:
• Value
• Pointer
• Reference
35. To what type are values converted internally
when evaluating a conditional statement?
Answers:
• tinyint
• negative
• positive
• boolean
• integer
36. var x = "foo"; x = !!x; What is the value of x?
Answers:
• "!!foo"
• NaN
• true
• undefined
37. What will calling the below test function log to
console? function test(){ console.log(a); var a = 'hello'; console.log(a); }
Answers:
•
undefined, "hello"
• ReferenceError: a is not
defined
• "",
"hello"
• ReferenceError: a is not
defined, "hello"
38. How do you assign an anonymous function to a
variable?
Answers:
• var anon = func({});
• var anon
= function() { };
• var anon = new Function
() { };
• var anon = func() { };
39. What is the value of x? var x = 2 + "2";
Answers:
• 4
• "4"
•
"22"
• 22
40. Which of these is not a JavaScript statement?
Answers:
• break
• None,
these are all valid statements.
• throw
• continue
41. Which of the following variable types does not
exist in JavaScript?
Answers:
• double
• string
• boolean
• number
• object
42. Which of the following is a way to add a new
value to the end of an array?
Answers:
• arr.length = value;
•
arr[arr.length] = value;
• arr[arr.length()] =
value;
• arr[value] = length;
43. What is the RegExp object constructor used for?
Answers:
• Match
text against regular expressions
• Switches numerical
notation to exponential
• Provides access to
Windows registry express values
• Regulates the expression
of variables
• Registers experienced
functions with the DOM
44. What does "2" + 3 + 4 evaluate to?
Answers:
• '234'
• 9
• '27'
45. When an array index goes out of bounds, what is
returned?
Answers:
• A default value, like 0
• the first or last value
in the array
• An error to the browser
• undefined
• Moderate
46. Which is the correct syntax to write array
literals in JavaScript?
Answers:
• var x =
["blank","blank","blank"];
• var x =
{"blank","blank","blank"};
• var x = new
Array(1:"blank",2:"blank",3:"blank")
• var x =
array("blank", "blank", "blank”);
47. The "exploit" property:
Answers:
• Is obsolete
• Represents a variable
• Does not
exist in JavaScript
• Is a very important
property
48. split() is a method of which constructors'
prototype?
Answers:
• Array.prototype
• None of these
•
String.prototype
• Number.prototype
49. Which of the following orders can be performed
with the Array prototype "sort()" callback?
Answers:
• Descending alphabetical
• ASCII ordering
• Ascending alphabetical
• All of
these
50. var a = {1:'one',2:'two',3:'three'}; var b = Object.keys(a); What's the value of
b?
Answers:
• An array
with all of the distinct keys from the obj a
• An obj with autowired
getters and setters for it's key/values
• none of the above
• A serialized copy of the
obj a
51. How do you write a conditional statement that
will *only* execute the contained code
if variable x has a value 5 of type *number*?
Answers:
• if x = 5 then ...
• if (x == 5) { ... }
• if x = 5 ...
• if (x ===
5) { ... }
52. What is the value of c? var a = function(){ this.b = 1; } var b = function(){ var b = new a().b; return 5 + b; } var c = b();
Answers:
• 5
• null
• Error thrown when running
the code
• undefined
• 6
53. How do you find the number with the highest
value of x and y?
Answers:
• ceil(x, y)
• Math.ceil(x, y)
• top(x, y)
•
Math.max(x, y)
• max(x, y)
54. What is the value of x? var a = false; var x = a ? “A” : “B”;
Answers:
• false
• "A"
• undefined
• true
•
"B"
55. Which of the following operators can assign a
value to a variable?
Answers:
• =
• All of
these
• +=
• %=
56. What is the value of x? var x = '1'+2+3;
Answers:
• 6
• The statement generates
an error.
•
"123"
• 15
57. Which of the following is the equivalent of the
following. if (a) { x = b; } else { x = c; }
Answers:
• x = a : b ? c;
• x = a ? b
: c;
• x = a ? b , c;
58. What is the value of x? var obj = {}; obj["function"] =
123; x = obj.function;
Answers:
• 123
• undefined. SyntaxError
due to illegal position of a reserved word
• native Function
constructor
• undefined. Silent
failure.
59. null === undefined
Answers:
• false
• true
60. Which event fires whenever a control loses
focus?
Answers:
• onmove
• onchange
• onblur
• onclick
61. Which of these is not a logical operator?
Answers:
• ||
• &
• !
• &&
62. Which of these operators compares two variables
by value AND type?
Answers:
• ==
• None of these
• =
• ===
63. Which message does the following log to the
console? bar(); function bar() { console.log('bar'); }
Answers:
• SyntaxErrror
• undefined
•
"bar"
• TypeError
64. Which of the following invokes a user-defined
object constructor function?
Answers:
• var x = create
myConstructor();
• var x =
new myConstructor();
• myConstructor x = create
myConstructor();
• myConstructor x = new
myConstructor();
65. The function call Math.ceil(3.5) returns:
Answers:
• 4
• 3
• 0
• Throws a MathError
exception.
66. In JavaScript, to call a function directly, you
use:
Answers:
• function_expression ->
( arguments_if_any )
•
function_expression ( arguments_if_any )
• function_expression {
arguments_if_any }
• arguments_if_any (
function_expression )
• ( arguments_if_any )
-> function_expression
67. How do you declare a function?
Answers:
• function:doSomething() {}
• all of these
• function=doSomething() {}
• function
doSomething() {}
68. How would one declare a string variable?
Answers:
• var fName =
"Mary";
• var names =
"7";
• Any of
these
• var fName = new String;
69. What is the value of a : var a = 3; var b = 2;
var c = a; var a=b=c=1;
Answers:
• true
• 3
• false
• 2
• 1
70. Properties of objects may be accessed using...
Answers:
• the redirect notation in
JavaScript.
• none of these
• the dot
notation in JavaScript.
71. What is the value of the array myArr after
execution of the following code: var
myArr = [1,2,3,4,5]; myArr.shift();
Answers:
• [2,3,4,5]
• [1,2,3,4,5]
• []
• [1,2,3,4]
72. What does isNaN() do?
Answers:
• Converts a non-numeric
value to a number.
• Throws an error if a
conditional statement is false.
• Only
returns true if the argument is not a number
73. What keyword is used to define the alternative
path to take in a conditional statement?
Answers:
• altenative
• next
• or
• else
74. What is the difference between a while loop and
a do...while loop?
Answers:
• The code inside a while
loop will always be executed at least once, even if the condition is false.
• The code
inside a do...while loop will always be executed at least once, even if the
condition is false.
• There is no difference
between them.
75. What is the difference between == and === ?
Answers:
• The == is used in
comparison, and === is used in value assignment.
• The ==
operator converts both operands to the same type, whereas === returns false for
different types.
• The === is deprecated,
and now they are exactly the same.
76. Which of these could be a correct way to create
an instance of Person?
Answers:
• var Person john = new
Person('John', 'Doe', 50, 'blue');
• new john = Person('John',
'Doe', 50, 'blue');
• Person john = new
Person('John', 'Doe', 50, 'blue');
• var john
= new Person('John', 'Doe', 50, 'blue');
77. (function( ) { var x = foo( ); function foo( ){ return "foobar" };
return x; })( ); What does this
function return?
Answers:
• TypeError: undefined is
not a function
•
"foobar"
• ReferenceError: foo is
not defined
• foo( )
• undefined
78. What operator is used for string concatenation?
Answers:
• &
• .
• All of these
• +
79. Which is the correct way to write a JavaScript array?
Answers:
• var names
= ["Tim","Kim","Jim"];
• var names = {1:
"Tim", 2:"Kim", 3:"Jim"};
• var names = {0:
"Tim", 1: "Kim", 2: "Jim"};
• var names =
array("Tim", "Kim", "Jim");
80. USERNAME and userName
Answers:
• Represent the name of the
same constant
• Represent the name of the
same variable
• Represent the name of
different constants
• Represent
the name of different variables
81. Which of these descriptors applies to
JavaScript?
Answers:
• Loosely
typed, values of any type can be assigned to any variable.
• Strongly typed, variables
are declared with a type, and you can not assign another type to the variable.
82. Which of the following is an Error object
constructor?
Answers:
• EvalError
• All of
these
• Error
• RangeError
83. How do you check what the type of a value in
variable x is?
Answers:
•
typeof(x);
• x.__type;
• gettype(x);
• Object.type(x);
84. Which of the following is a JavaScript comment?
Answers:
• \\ comment
• <!-- comment -->
• //
comment
• # comment
• -- comment
85. What is the value of the following
expression: 8 % 3
Answers:
• 5
• 24
• Other/Error
• 2
86. var a = '011'; parseInt(a); will return:
Answers:
• 9
• 0
• error
• 11
87. var a = '011'; parseInt(a); will return:
Answers:
• 9
• 0
• error
• 11
88. How does a "while" loop start?
Answers:
• while (i<=10;i++)
• while i=(1 <> 10)
• while
(i<=10)
• while i=1 to 10
89. The
`else` statement is ___
Answers:
• used inside of an `if`
statement. To specify the code that should execute if the `if` condition is no
longer true.
• Does not exist, in
JavaScript `or` and `then` are used to specify code to execute for the
"false" case of the `if` statement.
• used
together with the `if` statement to specify the code that should execute when
the `if` condition is false.
90. Given the following code, what does myFunc()
return? var foo = 'foo'; var bar =
'bar'; function myFunc() { return foo
+ bar; }
Answers:
• "foo + bar"
• An error is thrown
because of illegal out of scope access.
•
"foobar"
• NaN
•
"undefinedundefined"
91. String literals are written using:
Answers:
• Just double quotes:
"example"
• Either
double quotes or single quotes: "example" and 'example'
• Just single quotes:
'example'
92. How is an object property referenced?
Answers:
• myObj.foo
• myObj[foo]
• myObj<foo>
• myObj->foo
• myObj(foo)
93. Which symbol is not used in logical operations?
Answers:
• &&
• !
• ||
• %
94. Which of these will throw a SyntaxError?
Answers:
• if (x === 1) { }
• if (x == 1) { }
• if (x
==== 1) { }
• if (x = 1) { }
95. JavaScript supports dynamic typing, you can
assign different types of values to the same variable.
Answers:
• true
• false
96. How do you round the number 7.25, to the nearest
whole number?
Answers:
•
Math.round(7.25)
• Math.rnd(7.25)
• rnd(7.25)
• round(7.25)
97. How to return the first value of this
array? var myArr = [1, 2, 3, 4, 5]; var myVal = ...
Answers:
• myArr.unshift();
• myArr.shift();
• myArr[1];
• myArr.pop();
• myArr[0];
98. How do you define a function called
"fName"?
Answers:
• None of these
• function
fName() { }
• new fName = { }
• func fName = function ()
{}
• function fName: { }
99. Which of the following is not a reserved word?
Answers:
• program
• throw
• return
• void
100. Which of the following asserts that the
variables `A`, `B`, and `C` have unequal values?
Answers:
• A !== B & B !== C
• A !== B || B !== C
• A !== B
&& B !== C && A !== C
• A !== B
101. What does the "break" statement do?
Answers:
• Aborts
the current loop or switch statement.
• Simulates a JavaScript
crash.
• Aborts the current
function.
• Cancels the current
event.
102. Which of the following is a valid function
definition?
Answers:
• func myFunc = (arg1 as
string, arg2 as int) { }
• function myFunc(arg1,
arg2):
• function
myFunc(arg1,arg2) { }
103. Which of the following declares a variable with
a value of string type?
Answers:
• var myVar
= "This is a string";
• var string myVar =
"This is a string";
• string myVar = "This
is a string";
104. Are variable identifiers case-sensitive?
Answers:
• Yes
• No
105. What is the correct JavaScript syntax to insert
a comment that can span multiple lines?
Answers:
• // This comment has more
than one line //
• // This comment has mor
than one line *//
• / This comment has more
than one line /
• /* This
comment has more than one line */
106. The "if" statement is used to:
Answers:
• Convert an integer value
to a boolean
• Deal with
logic that should execute only when a condition is true
• Deal with logic that
should execute only when a condition is false
• Create a loop that runs
as long as a condition is true
107. Which keyboard character represents the
assignment operator?
Answers:
• !
• ?
• =
• #
• :
108. String concatenation...
Answers:
• is the splitting of a
String into two or more Strings
• Is a complex String
• Is an elemental String
• Is the
combination of two or more text Strings
109. Properties of a RegExp object include:
Answers:
• ignoreCase
• source
• All of
these
• lastIndex
110. You use the Math.pow() method to:
Answers:
• Return a
number raised to the power of a second number
• Return any number
• Return a variable value
• Return a random value
between 0 and 1
111. What is the value of ("dog".length)?
Answers:
• 2
• 3
• 4
112. Which is NOT a way to create a loop in
javascript?
Answers:
• for (...) { }
• repeat
(...) { }
• while (...) { }
• do { } while(...)
113. What is the value of x? var a = "A"; var x =
a.concat("B");
Answers:
• "B"
•
"AB"
• "A"
• ["A", "
B"];
114. Which statement loops through an array?
Answers:
• for (i = 0; i <=
myArray.length;)
• for (var
i=0; i < myArray.length; i++)
• for (i <
myArray.length; i++)
115. The var statement is used to:
Answers:
• Declare a member of a
class
• Retrieve a variable
descriptor
• Change a constant
• Create a
new local variable
116. function foo(){ var tmp = 'one_two_three_four_five'; return tmp.replace(/_/g, '+'); } What does foo() return?
Answers:
• one+
• one+two_three_four_five
• one_two_three_four_five
•
one+two+three+four+five
• _______________________
117. A for loop is written as such: "for (first
property; second property; third property) {...}" What does the third property represent?
Answers:
• A condition to check at
the beginning of a loop cycle
• An action
to take at the end of the current loop cycle
• An action to take at the
beginning of the loop cycle
118. Where do you use the "break"
statement?
Answers:
• To add a value to an
array.
• To
terminate a switch statement, loop, or labeled block.
• To terminate an Object
statement.
• To delete a (global)
variable.
• To divide (or
"break") a mathematical value in half.
119. In an array object, what is the key of the
first value?
Answers:
• $
• -1
• 0
• 1
• 100
120. Which of the following primitive values exist
in JavaScript?
Answers:
• boolean
• string
• All of
these
• number
121. What keyword is used to begin a conditional
statement?
Answers:
• how
• condition
• if
• when
122. What character ends a javascript statement?
Answers:
• A period ".".
• A
semicolon ";".
• A colon ":".
• An exclamation mark
"!".
123. Which has the correct syntax of a ternary
operation?
Answers:
• var x = y
=== true ? "true" : "false";
• var x = ( y === true ) :
"true" ? "false";
• var x = y === true :
"true" ? "false";
• var x = ( y === true ) {
"true" : "false" };
124. JavaScript is an implementation of the ______
language standard.
Answers:
• HTML
• ActionScript
• VBScript
•
ECMAScript
125. If a function doesn't explicitly use the
"return" operator, what will the return value be when the function is
invoked?
Answers:
• NaN
• null
• closure
• undefined
• false
126. What is result of the following expression: var
a = "test"; console.log(!!a);
Answers:
• SyntaxError
• undefined
• true
• false
127. What is the name of the String prototype that
appends the given string to the base string and returns the new string?
Answers:
•
"x".concat("foo")
•
"x".add("foo")
• None of these does that
and/or such method doesn't exist in javascript!
• "x".combine("foo")
•
"x".match("foo")
128. Which of these is a correct method to create a
new array?
Answers:
• var myArray = ();
• var myArray = array();
• var
myArray = [];
• var myArray = new
Array[];
• var myArray = {};
129. var data =
["A", "B", "C", "D"];
data.unshift("X"); data.push("Y"); What does data look
like?
Answers:
• ["A",
"B", "C", "D", "X", "Y"]
•
["X", "A", "B", "C", "D",
"Y"]
• ["A",
"B", "C", "X", "D", "Y"]
• ["Y",
"A", "B", "C", "D", "X"]
• ["X",
"Y", "A", "B", "C", "D"]
130. What character combination is used to create a
single line comment?
Answers:
• !!
• $$
• --
• //
131. Which of the following is the syntax for an
object literal (with no properties)?
Answers:
• [];
• object;
• {};
• nil;
• ();
132. How can you concatenate multiple strings?
Answers:
• 'One' + 'Two' + 'Three'
• Both of
these
• 'One'.concat('Two',
'Three')
133. How do you assign object properties?
Answers:
•
obj["age"] = 25 OR obj.age = 25
• obj.age = 25 OR
obj(@"age") = 25
• obj(age) = 25 OR obj.age =
25
134. Consider this code: var x = ['Hello']; What value will 'x[1]' return?
Answers:
• "Hello"
• NULL
• undefined
• null
• ['Hello']
135. The _______ operator returns a string that
identifies the type of its operand.
Answers:
• typename
• getType
• Type
• TypeOf
• typeof
136. When writing an object literal, what is used to
separate the properties from each other?
Answers:
• a colon ":"
• a comma
","
• a full-stop "."
• a semicolon ";"
• an underscore
"_"
137. What are curly braces ("{" and
"}") used for?
Answers:
• Invoking a function
• Defining a class
• Parsing JSON
• Block
declarations and object literals
• Setting attributes
138. What is the value of x? function foo(y) { var z = 10;
z = 7; }; var x =
foo("bar");
Answers:
• "bar"
• undefined
• 7
• null
• 10
139. How do you create an object in JavaScript?
Answers:
• All of
these work.
• var obj = {};
• var obj = new Object();
• function Foo() {} var obj
= new Foo();
140. Which of the following is not a method in the
"JSON" object according to the ECMAScript specification?
Answers:
• JSON.parse
• JSON.stringify
•
JSON.fromString
141. How can you get the number of characters in a
string ?
Answers:
•
"1234567".getLength()
•
"1234567".length
•
"1234567".Length
•
"1234567".length()
•
"1234567".Length()
142. What is the result of the following statement:
0 == "";
Answers:
• null
• false
• true
• Throws Error, invalid
comparison
143. What does null, undefined, "string",
20, true and false have in common?
Answers:
• they are
primitive values
• they have the same
instance properties
• they are objects
• they are functions
144. Given the following code, what is the value of
x? var x = ['foo', 'bar']; x.length = 1;
Answers:
• []
• ["bar"]
• ["foo",
"bar', 1]
• ["foo",
"bar"]
•
["foo"]
145. Math.random() returns..
Answers:
• a random number between 0
and 1000
• a random
number between 0 and 1
• a random number that can
be any value
• a random number between 0
and 100
146. What is the result of the following
expression? ({"foo":
true}).foo;
Answers:
• true
• false
• 4
• SyntaxError
• undefined
147. In the loop, "for (first clause; second
clause; third clause) { statements; }" What does the second clause
represent?
Answers:
• Code to execute once,
after the loop has ended
• Code to execute once,
before the loop starts
• A condition to check at the
end of each loop cycle
• A
condition to check at the beginning of each loop cycle
148. What is the value of `x` after the
following? var x = "hello";
(function() { x =
"goodbye"; }());
Answers:
• "hello"
• undefined. A SyntaxError
is thrown
• "goodbye"
149. Which is not a primitive data type in
JavaScript?
Answers:
• character
• number
• boolean
• string
150. What will invoking `foo` return? function foo() { var x = 10; x = 7;
};
Answers:
• undefined
• foo
• 10
• 7
• null
151. What is the value of x? var str = "what is this"; var x =
str.search("is");
Answers:
• 4
• 7
• 6
• 1
• 5
152. The "this" keyword refers to ...
Answers:
• parent object that hosts
the current function.
• current
execution context (could be any value).
• function currently being
executed.
153. '&' Operator is _____
Answers:
• a displacement bit
operator
• an operator used in
conditionals
• an assignment operator
• a bitwise
operator
154. What character combination is used to alter the
order of operations by grouping expressions?
Answers:
• < >
• [ ]
• ( )
• { }
155. var x = Math.ceil(10.126); What is the value of x?
Answers:
• An error, because it was
called incorrectly
• 10.13
• 10
• 11
156. What is the type of `null`, according to the
`typeof` operator?
Answers:
•
"object"
• "null"
• "array"
• "undefined"
157. function b(x, y, a) { arguments[2] = 10; alert(a); } b(1, 2, 3); What is alerted?
Answers:
• 10
• 1
• 2
• 3
158. What is the difference between using call() and
apply() to invoke a function with multiple arguments?
Answers:
• apply() is deprecated in
favor of call()
• apply()
is identical to call(), except apply() requires an array as the second
parameter
• apply() is identical to
call(), except call() requires an array as the second parameter
• apply() is exactly
identical to call()
159. var y = 3, x = y++; What is the value of x?
Answers:
• 5
• 2
• 4
• 6
• 3
160. Which of the following types does NOT exist in
javascript?
Answers:
• object
• number
• boolean
• string
• integer
161. What is the end value of myAddedVar with the
following code: var myVar = '5'; var
myAddedVar = myVar + 10;
Answers:
• 15
• '510'
• 510
• Nothing, the code will
result in an error.
• NaN
162. What does this line do? variable++;
Answers:
• Increments the value of
"variable" and returns the new value
• Returns a value 1 greater
than "variable" without changing its value
• Adds the value of
"variable" to itself
• Returns an error to the
browser
•
Increments the value of "variable" but returns the previous value
163. var a = new Boolean(false); What is (typeof a)?
Answers:
• 'boolean'
• 'false'
• 'number'
• 'primitive'
• 'object'
164. What is the value of x? var x = typeof new String("abc");
Answers:
• undefined
• string
• object
165. Which of these will invoke a function?
Answers:
• function.Execute(...)
• function.Apply(...)
•
function.apply(...)
• function.exec(...)
• function.invoke(...)
166. Does NaN equal itself?
Answers:
• No, when trying to
compare it against itself, an exception is thrown.
• Yes, just like 123 is
equal to (==) 123, NaN is equal to NaN.
• No, NaN
does not equal itself (== comparison would return false).
167. What will happen in the console after executing
this code? if ("foo") { console.log("foo" ===
false); console.log("foo"
=== true); }
Answers:
• false
false
• TypeError : Cannot
convert to boolean
• NaN NaN
• false true
168. What is the value of the function log? var _ = '_'; log(parseInt(_));
Answers:
• NaN
• '/e242'
• SyntaxError: Unexpected
identifier
• 242
• TypeError: incorrect type
of argument, expected Number but was String.
169. Which of these is not a built-in object
constructor?
Answers:
• Time
• RegExp
• Array
• Date
170. Given the following code: var myVar = '5'; var myAddedVar = myVar +
10; What is the value of
(myAddedVar.constructor === Number)?
Answers:
• undefined
• NaN
• Type Error
• true
• false
171. How would you iterate over the following object?
var my_data = {a: 'Ape', b: 'Banana', c: 'Citronella'};
Answers:
• None of these. One can
only iterate over arrays, not objects.
• for (var i = 0; i <
my_data.length; i++) {}
• foreach (my_data as key
=> value) {}
• for (var
key in my_data) {}
172. What is the value of x after the following code
is executed? var x = 0; x = x++;
Answers:
• 0
• 1
173. You use the Math.tan( ) method to:
Answers:
• Return the tangent of an
angle (in gradients)
• Return
the tangent of an angle (in radians)
• Return the tangent of an
angle (in degrees)
• Does not exist in
JavaScript
174. A javascript variable prefixed with a $ is:
Answers:
• still valid, but
deprecated since Javascript 1.6
• valid
javascript syntax as any other character
• invalid, a common bug
introduced by developers coming from PHP or Perl
• only valid within certain
javascript libraries
175. Math.min() < Math.max(); ...will return:
Answers:
• false
• true
176. Math.min() < Math.max(); will return
Answers:
• true
• undefined
• null
• false
177. What does the following expression return? 1 + 5 + " bottles of milk";
Answers:
• undefined. An exception
is thrown
• "6
bottles of milk"
• "15 bottles of
milk"
• "5 bottles of
milk"
178. Which Object method takes a `propertyName`
parameter and returns `true` if the object contains an uninherited property
with that key?
Answers:
•
obj.exists('propertyName');
•
obj.hasOwnProperty('propertyName');
•
obj.contains('propertyName');
• obj.doesPropertyExist('propertyName');
•
obj.hasProperty('propertyName');
179. var foo
= "Global"; function fun() { log( foo ); var foo = "Local"; log( foo ); } fun(); What the output of the above to log()?
Answers:
• Global Local
• Global Global
• Local Local
• undefined
Local
180. Which of the following is NOT a valid way to
write a loop that will iterate over the values in the array in variable
"myArray"?
Answers:
• for (var i = 0, len =
myArray.length; i < len; i++) {}
• None of
these, they are all valid
• for (var i = 0; i <
myArray.length; i++) {}
• var i = 0; for (; i <
myArray.length; i++) {}
• for (var i = 0; i <
myArray.length; i += 1) {}
181. What is the value of c? var A = function () { this.b = 1; } A.prototype.b = 2; var c =
new A().b;
Answers:
• 2
• Can be 1 or 2
• 1
• SyntaxError thrown when
running the code
182. What will be the value of x? function A() { this.do = function () { return 'foo'; }; } A.prototype = { do: function () { return 'bar'; } }; var x =
new A().do();
Answers:
•
"foo"
• "bar"
• undefined
• Throw an Error
183. What is the right way to combine two arrays
into a new array? var a =
["a", "b", "c"]; var b = ["d",
"e", "f"];
Answers:
• var c = a.join(b);
• var c =
a.concat(b);
• None of these
• var c = a.push() +
b.push();
184. What is the output? var one; var two = null; console.log(one ==
two, one === two);
Answers:
• false false
• true
false
• false true
• Error: one is not defined
• true true
185. Which are the different ways to affect the
"this" reference in a function?
Answers:
• Direct attribution, e.g.
this = x;
• Invoking
a function with the "new" keyword, invoking through the .call()
method, invoking through the .apply() method.
• the "this"
keyword is a global reference that always has the same value.
• Only by invoking through
the .call() or .apply() method.
• Only by invoking a
function with the "new" keyword
186. What is the difference between the two
declaration methods below? var functionOne
= function() { /* some code */ } function functionTwo() { /* some code */ }
Answers:
• No difference, they are
treated the same way by the javascript engine. Different syntax to do the same.
•
functionOne is defined in-place (until that line, functionOne is undefined),
whereas functionTwo is hoisted to the top of the scope and is available as a
function throughout the scope.
• functionOne is not a
correct way to define functions
• functionTwo is defined
in-place (until that line, functionTwo is undefined), whereas functionOne is
hosted to the top of the scope and is available as a function throughout the
scope.
187. How does JavaScript interpret numeric constants
outside of strict mode?
Answers:
• As octal
if they are preceded by a zero, and as hexadecimal if they are preceded by a
zero and "x"
• None of these are correct
• As hexadecimal if they
are preceded by a zero only
• As octal if they are
preceded by an underscore
188. When reserved words are used as keys in object
literals they must be ______?
Answers:
• Prefixed with the @
operator
• quoted
• escaped
• This is not possible in
javascript
189. Mathematical expression, "10" -
(12+5).toString(), evaluates to what?
Answers:
• -7
• 3
• Throws Javascript error
• 10125
190. What does the following return? Number(null);
Answers:
• 0
• 1
• undefined
• null
191. What is the value of x.length after running
this code? x = ["foo"]; x.quux
= "Hello"; x[1] = "bar";
Answers:
• 1
• Error on last line: index
out of bounds
• 2
• 3
• Error on middle line:
cannot add properties to Array
192. What is the value of x after the code below is
executed? var x = ""; function
foo() { x += "foo "; } var
bar = function() { x += "bar
"; }; foo(); var quux = bar = foo; quux();
Answers:
• "foo bar "
• "bar "
• "foo
foo "
• "foo bar"
193. What will be in console after executing this
code: console.log(1 + '1' - 1);
Answers:
• 10
• '1'
• '111'
• 1
194. The expression (typeof NaN === "number")
evaluates to:
Answers:
• false
• true
• Throws an Error
195. What will: typeof typeof(null) return?
Answers:
• null
• Number
• error
• string
• empty
196. What will the expression a === b return after
the following? var a = { "foo": "bar"
}; var b = { "foo": "bar" };
Answers:
• An exception is thrown.
• true
• undefined
• false
197. How can you remove an element from an array and
replace it with a new one ?
Answers:
• array.split(...)
•
array.splice(...)
• array.switch(...)
• array.overwrite(...)
• array.replace(...)
198. What will we see in the console after the
following code run: var a = 'Bolt'; function f() { if (!a) { var
a = 'Nut'; } console.log(a); } f(); console.log(a);
Answers:
• 'Bolt' and 'Bolt'
• 'Nut' and 'Nut'
• 'Nut' then
'Bolt'
• 'Bolt' then 'Nut'
199. true + true will return :
Answers:
• undefined
• true
• 2
200. What is the result of: function foo() { output( "biz " + bar() ); }
bar(); var bar = function() {
return "baz"; }
Answers:
• foo baz
• biz bar
•
TypeError: Undefined is not a function
• biz baz
• baz biz
201. What is the value of x? var x = 10/0;
Answers:
• 0
• Infinity
• Runtime exception
• NaN
202. What will be the result of this expression:
void 0
Answers:
• null
• undefined
• SyntaxError
• TypeError
203. What does Math.random() do?
Answers:
• Returns a random number
more than 0 and less than 1.
• Returns a
random number from and including 0 to less than 1.
• Returns a random number
more than 0 up to and including 1.
• Randomly selects a number
1-10.
• Randomly put numbers in
descending and ascending order
204. In the following code: function test() { var foo = bar = 5; } test();
Answers:
• SyntaxError is thrown
• Variable
foo is a local variable. But bar is a global variable.
• Both foo and bar are
global variables.
• Both foo and bar are
local variables.
205. What are the values of x and y after the
invocation of `foo` in following? var x = "I am global x"; var y =
"I am global y"; function
foo() { var y = x = "Hello from
foo"; } foo();
Answers:
• x = "I am global
x"; y = "I am global y";
• x =
"Hello from foo"; y = "I am global y";
• The function throws a
SyntaxError
• x = "Hello from
foo"; y = "Hello from foo";
206. var q = null;
q++; What is q?
Answers:
• Type Error
• null
• 1
• NaN
207. Given the following code, what will
myFunction(123, false, "test") return? function myFunction(param) { return arguments[1] || param; }
Answers:
• false
• undefined
• 123
• true
• "test"
208. After the following code: var a = function(){ this.b = 1; this.deleteMe = function(){ delete this; } }; var c = new a(); c.deleteMe(); What is the value of (String(c))?
Answers:
• [object
Object]
• null
• Error thrown
• (empty)
• undefined
209. Which operator has highest precedence?
Answers:
• +
• -
• ^
• *
210. function Question() { this.answered = false; } Question.prototype.rightAnswer = 5; console.log( new Question().rightAnswer, Question.rightAnswer ); What gets printed to the console?
Answers:
• undefined 5
• 5 5
• undefined undefined
• 5
undefined
211. What will the console log when running this
code? Function.prototype.a = 1; var a =
new Function(); a.prototype.a = 2; var c = new a(); console.log(a.a , c.a);
Answers:
• Error thrown when running
the code
• 1 2
• 2 1
• 2 2
• 1 1
212. Evaluate:
undefined + 2
Answers:
• NaN
• 2
• undefined
• Type Error
213. Evaluate:
new Boolean(new Boolean(false)).valueOf()
Answers:
• true
• false
• Type Error
• undefined
• (Instance of object
Boolean with valueOf false)
214. An (inner) function enjoys access to the
parameters and variables of all the functions it is nested in. This is called:
Answers:
• Lexical
scoping
• Prototypal inheritance
215. Object.keys(x)
Answers:
• returns all properties of
x as an array of strings, including non-enumerable properties.
• Incorrect syntax for
using Object.keys.
• returns a key that can be
used to unlock the object after Object.freeze(x).
• returns
the enumerable properties of x as an array of strings.
216. "bar".split().length returns:
Answers:
• throws an error
• 3
• 1
• 2
217. Math.Pi returns the mathematical constant of
Pi. What standard JavaScript method would truncate Math.Pi to 3.14 ?
Answers:
•
Math.Pi.toString("D2")
• Math.Pi.toPrecision(2)
• Math.Round(Math.Pi)
•
Math.Pi.toFixed(2)
218. function foo(){ var tmp = 'one_two_three_four_five'; return tmp.replace('_', '+'); } What does foo() return?
Answers:
• one_two_three_four_five
• one+two+three+four+five
• one+two_three_four_five
• one+
• one_
219. var x = { foo: "A" };
x.constructor.prototype.foo = "B"; var y = {}; console.log(x.foo);
console.log(y.foo); Which two values
will be logged?
Answers:
• "B" undefined
• "B"
"B"
•
"A" "B"
• "A" undefined
• "A"
"A"
220. Evaluate the following expression: ~-(2 + "2")
Answers:
• 23
• 22
• -22
• true
• 21
221. Which of these will create a copy of an array
such that changes to the old array will not be reflected in the new array?
Answers:
• var newArray = new
Array(oldArray);
• var newArray =
[oldArray];
• var newArray = oldArray;
• var
newArray = oldArray.slice(0);
222. What is the output of the following? var x = 1;
console.log(x++ + ++x + x);
Answers:
• 3
• 6
• 7
• 4
223. console.log( ~[]+~![]+~!![] ); Console output is:
Answers:
• NaN
• 4
• undefined
• -4
• -3
224. What value is passed to function
"foo" as first argument? foo(
+"5" );
Answers:
• "05"
• 5
• "5"
• NaN
• 0
225. What will be printed to the console as a result
of this code? var printName = function()
{ console.log('Matt'); printName = function() { console.log('James'); }; }; var copy = printName; printName();
copy();
Answers:
• Matt Matt
• James Matt
• Matt James
• James James
226. What is the result of: console.log((!+[]+[]+![]).length);
Answers:
• 4
• 0
• 9
• syntax error
• 18
227. What is the value of x after the following code
is run? var obj = { 0: 'who', 1: 'what',
2: 'idontknow'}; var x = 1 in obj;
Answers:
• "who"
• Nothing, the code throws
a syntax error
• "what"
• true
• undefined
228. Which of the following String prototype method
takes a regular expression?
Answers:
• indexOf()
• search()
• All of these
• charCodeAt()
229. What is the value of mike after this code is
run? function Person(name, age) { this.name = name; this.age = parseInt(age, 10); } var mike = Person('Mike', '25');
Answers:
• { name: 'Mike', age: 25 }
• This code won't run. It
throws a SyntaxError.
• undefined
• { name: 'Mike', age: '25'
}
• null
230. var x = ([]+!![])[+!+[]]; What is the value of x?
Answers:
• []
• 'a'
• Syntax Error
• 'r'
• undefined
231. Which of the following expressions evaluates to
false?
Answers:
• new Boolean(0) == 0
• new
Boolean('false') == false
• new Boolean(1) == 1
• They're all evaluate to
true
• new Boolean('true') ==
true
232. Math.log(x) returns:
Answers:
• Logarithm
base e (Euler's number) of x.
• Logarithm base 8 of x.
• Logarithm base 2 of x.
• Logarithm base 10 of x.
233. Which of the following is not a reserved word
in the language?
Answers:
• and
• instanceof
• debugger
• while
234. What is the result of the below expression?
Assume output is a function that outputs a line of text. output(typeof
(function() {output("Hello World!")})());
Answers:
• Hello
World! undefined
• undefined Hello World!
• function
• string
• object
235. What is the value of "x" after the
following code runs? var x; x++;
Answers:
• 0
• undefined
• NaN
• Throws a TypeError on the
"x++;" statement
• 1
236. function foo() { this = "foo"; } var a = foo(); What will the preceding code produce?
Answers:
• undefined
•
ReferenceError: Invalid left-hand side in assignment
• SyntaxError: Unexpected
token
• "foo"
• "undefined"
237. What will this code produce: +new Date()
Answers:
• Unix
timestamp in milliseconds (UTC timezone)
• Unix timestamp in
milliseconds (Local timezone)
• A SyntaxError
• The Unix epoch
(1970-01-01 00:00:00)
238. What is the value of c? var a = function(){ this.b = 1; } var b = function(){ this.b = new a().b; return 5; } var c = b() + new b();
Answers:
• 5
• 1
• Error
thrown when running the code
• 6
• [object]
239. Which of the following Array prototype method
actually modifies the array it's been called on?
Answers:
• splice()
• slice()
• all of them
• concat()
240. What does the following return? Math.max();
Answers:
• Infinity
• -Infinity
• 0
• null
241. Which are the different value types in JavaScript?
Answers:
• boolean, integer, float,
string, array, object and null
• boolean, number, string,
function, object, null and undefined
• boolean, number, date,
regexp, array and object
• boolean,
number, string, function, object and undefined
242. String values have a "length"
property. Why is this property not included in a for-in loop over a string
object? var prop, str; str = 'example'; /* str.length === 7 */ for ( prop in str) {}
Answers:
• Because the
"length" property isn't a real property (defined and set through
get/set accessors). Properties with accessors are not included in for-in loops.
• Because the
"length" property is only in the String prototype, it is not an own
property of string objects, and as such is not included in a for-in loop.
• Because
the "length" property has internal [[Enumerable]] set to false.
243. What will the following code, when evaluated,
do? var void = function () {};
Answers:
• Create a local variable
named "void" but stays undefined due to a SyntaxError.
• Throw a
SyntaxError
• Assign an anonymous
function to variable named "void"
244. Object("s") instanceof String ===
"s" instanceof String
Answers:
• true
• false
245. What's the correct syntax for creating a Date
object for January 10, 1998?
Answers:
• new Date(1998, 1, 10);
• new Date(1, 10, 1998);
• new
Date(1998, 0, 10);
• new Date(0, 10, 1998);
246. Evaluate: ![]+[]
Answers:
• Syntax Error
• 'false'
• true
• false
• undefined
247. What is the value of x? var a = "abc"; var x = a instanceof
String;
Answers:
• true
• false
248. Which of the following is NOT a reserved word
in JavaScript?
Answers:
• implements
• goto
• super
• abstract
• array
{ 0 comments... read them below or add one }
Post a Comment