Elance Javascript Test Answers 2015



JavaScript is ...
subjective
objective
evil
object based


var obj1 = {}; var obj2 = {}; What is the value of (obj1 === obj2)
true
false


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>
The inner loop resets the outer for-loop, leaving it a fixed position each time, causing an infinite loop (hint: no block scope).
The outer-loop finishes after the first iteration due to a "bug" that unfortunately is part of the ECMAScript specification.
There is no bug. The loop will run correctly.
Uncaught SyntaxError.


What does the following expression return? 1 + 5 + " bottles of milk";
"15 bottles of milk"
"6 bottles of milk"
undefined. An exception is thrown
"5 bottles of milk"


How do you create an object in JavaScript?
var obj = {};
function Foo() {} var obj = new Foo();
All of these work.
var obj = new Object();


What is the result of the following statement: typeof "x";
"character"
"[object String]"
Throws error "ReferenceError: x is not defined"
"string"
"undefined"


Primitive types are passed by :
Value
Pointer
Reference


Which is not a primitive data type in JavaScript?
boolean
number
string
character


Which of these is a correct method to create a new array?
var myArray = ();
var myArray = [];
var myArray = new Array[];
var myArray = {};
var myArray = array();


To what type are values converted internally when evaluating a conditional statement?
positive
negative
integer
tinyint
boolean


Which of these is not a logical operator?
!
&
&&
||


What is the value of x? var a = false; var x = a ? “A” : “B”;
undefined
true
"A"
"B"
false


Which of the following variable types does not exist in JavaScript?
boolean
number
object
double
string


How do you write a conditional statement that will *only* execute the contained code if variable x has a value 5 of type *number*?
if (x == 5) { ... }
if x = 5 ...
if (x === 5) { ... }
if x = 5 then ...


Which event fires whenever a control loses focus?
onclick
onmove
onblur
onchange


Which of the following invokes a user-defined object constructor function?
var x = new myConstructor();
var x = create myConstructor();
myConstructor x = create myConstructor();
myConstructor x = new myConstructor();


The function call Math.ceil(3.5) returns:
Throws a MathError exception.
4
0
3


How is an object property referenced?
myObj(foo)
myObj->foo
myObj<foo>
myObj.foo
myObj[foo]


Which of these operators compares two variables by value AND type?
===
None of these
==
=


How would one declare a string variable?
Any of these
var fName = "Mary";
var names = "7";
var fName = new String;


function foo(){ var tmp = 'one_two_three_four_five'; return tmp.replace(/_/g, '+'); } What does foo() return?
one_two_three_four_five
_______________________
one+
one+two_three_four_five
one+two+three+four+five


USERNAME and userName
Represent the name of the same variable
Represent the name of different variables
Represent the name of different constants
Represent the name of the same constant


Which of these could be a correct way to create an instance of Person?
var Person john = new Person('John', 'Doe', 50, 'blue');
var john = new Person('John', 'Doe', 50, 'blue');
new john = Person('John', 'Doe', 50, 'blue');
Person john = new Person('John', 'Doe', 50, 'blue');


Which is the correct way to write a JavaScript array?
var names = {0: "Tim", 1: "Kim", 2: "Jim"};
var names = {1: "Tim", 2:"Kim", 3:"Jim"};
var names = ["Tim","Kim","Jim"];
var names = array("Tim", "Kim", "Jim");


Which of the following asserts that the variables `A`, `B`, and `C` have unequal values?
A !== B || B !== C
A !== B & B !== C
A !== B && B !== C && A !== C
A !== B


The `else` statement is ___
Does not exist, in JavaScript `or` and `then` are used to specify code to execute for the "false" case of the `if` statement.
used inside of an `if` statement. To specify the code that should execute if the `if` condition is no longer true.
used together with the `if` statement to specify the code that should execute when the `if` condition is false.


The "if" statement is used to:
Deal with logic that should execute only when a condition is false
Convert an integer value to a boolean
Create a loop that runs as long as a condition is true
Deal with logic that should execute only when a condition is true


String literals are written using:
Just single quotes: 'example'
Either double quotes or single quotes: "example" and 'example'
Just double quotes: "example"


How to return the first value of this array? var myArr = [1, 2, 3, 4, 5]; var myVal = ...
myArr[0];
myArr.pop();
myArr[1];
myArr.shift();
myArr.unshift();


How does a "while" loop start?
while i=(1 <> 10)
while i=1 to 10
while (i<=10)
while (i<=10;i++)


Properties of a RegExp object include:
source
ignoreCase
lastIndex
All of these


What is the value of the following expression: 8 % 3
5
2
24
Other/Error


Given the following code, what does myFunc() return? var foo = 'foo'; var bar = 'bar'; function myFunc() { return foo + bar; }
"foobar"
NaN
"undefinedundefined"
An error is thrown because of illegal out of scope access.
"foo + bar"


Which symbol is not used in logical operations?
||
%
&&
!


How do you round the number 7.25, to the nearest whole number?
Math.round(7.25)
rnd(7.25)
round(7.25)
Math.rnd(7.25)


Which of these will throw a SyntaxError?
if (x == 1) { }
if (x = 1) { }
if (x ==== 1) { }
if (x === 1) { }


What is the correct JavaScript syntax to insert a comment that can span multiple lines?
// This comment has mor than one line *//
/ This comment has more than one line /
// This comment has more than one line //
/* This comment has more than one line */


JavaScript supports dynamic typing, you can assign different types of values to the same variable.
true
false


How do you define a function called "fName"?
function fName: { }
func fName = function () {}
function fName() { }
new fName = { }
None of these


How do you check what the type of a value in variable x is?
gettype(x);
x.__type;
Object.type(x);
typeof(x);


Which of the following is not a reserved word?
throw
void
program
return


Which keyboard character represents the assignment operator?
!
?
#
:
=


Which of the following is a valid function definition?
function myFunc(arg1,arg2) { }
func myFunc = (arg1 as string, arg2 as int) { }
function myFunc(arg1, arg2):


String concatenation...
is the splitting of a String into two or more Strings
Is a complex String
Is the combination of two or more text Strings
Is an elemental String


What is the value of ("dog".length)?
4
3
2


What is the value of x? var a = "A"; var x = a.concat("B");
"B"
"A"
"AB"
["A", " B"];


Which is NOT a way to create a loop in javascript?
for (...) { }
do { } while(...)
while (...) { }
repeat (...) { }


In an array object, what is the key of the first value?
0
$
1
-1
100


Which statement loops through an array?
for (i < myArray.length; i++)
for (i = 0; i <= myArray.length;)
for (var i=0; i < myArray.length; i++)


Where do you use the "break" statement?
To divide (or "break") a mathematical value in half.
To add a value to an array.
To delete a (global) variable.
To terminate an Object statement.
To terminate a switch statement, loop, or labeled block.


The var statement is used to:
Create a new local variable
Retrieve a variable descriptor
Declare a member of a class
Change a constant


What does the "break" statement do?
Cancels the current event.
Aborts the current function.
Aborts the current loop or switch statement.
Simulates a JavaScript crash.


What character ends a javascript statement?
An exclamation mark "!".
A semicolon ";".
A period ".".
A colon ":".


Which of the following primitive values exist in JavaScript?
boolean
string
number
All of these


Are variable identifiers case-sensitive?
No
Yes


Which of the following declares a variable with a value of string type?
var string myVar = "This is a string";
var myVar = "This is a string";
string myVar = "This is a string";


You use the Math.pow() method to:
Return any number
Return a number raised to the power of a second number
Return a random value between 0 and 1
Return a variable value


What keyword is used to begin a conditional statement?
when
how
if
condition


What character combination is used to create a single line comment?
!!
--
$$
//


Java script start with......
Do_script
Start_script
<script>
<scr>


var a = '011'; parseInt(a); will return:
11
0
9
error


null === undefined
true
false


What is the value of the array myArr after execution of the following code: var myArr = [1,2,3,4,5]; myArr.shift();
[1,2,3,4,5]
[]
[2,3,4,5]
[1,2,3,4]


What does isNaN() do?
Only returns true if the argument is not a number
Converts a non-numeric value to a number.
Throws an error if a conditional statement is false.


Properties of objects may be accessed using...
the dot notation in JavaScript.
none of these
the redirect notation in JavaScript.


What keyword is used to define the alternative path to take in a conditional statement?
or
else
altenative
next


What is the difference between a while loop and a do...while loop?
The code inside a do...while loop will always be executed at least once, even if the condition is false.
The code inside a while loop will always be executed at least once, even if the condition is false.
There is no difference between them.


Which of these descriptors applies to JavaScript?
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.


What operator is used for string concatenation?
.
+
All of these
&


(function( ) { var x = foo( ); function foo( ){ return "foobar" }; return x; })( ); What does this function return?
TypeError: undefined is not a function
"foobar"
ReferenceError: foo is not defined
undefined
foo( )


Which of the following is a JavaScript comment?
-- comment
<!-- comment -->
// comment
\\ comment
# comment


What is the difference between == and === ?
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.


A for loop is written as such: "for (first property; second property; third property) {...}" What does the third property represent?
An action to take at the end of the current loop cycle
A condition to check at the beginning of a loop cycle
An action to take at the beginning of the loop cycle


What is the value of a : var a = 3; var b = 2; var c = a; var a=b=c=1;
3
true
1
false
2


Which of the following orders can be performed with the Array prototype "sort()" callback?
Ascending alphabetical
Descending alphabetical
ASCII ordering
All of these


When an array index goes out of bounds, what is returned?
undefined
An error to the browser
Moderate
the first or last value in the array
A default value, like 0


Which of the following is the equivalent of the following. if (a) { x = b; } else { x = c; }
x = a : b ? c;
x = a ? b : c;
x = a ? b , c;


Which message does the following log to the console? bar(); function bar() { console.log('bar'); }
undefined
TypeError
SyntaxErrror
"bar"


Which is the correct syntax to write array literals in JavaScript?
var x = ["blank","blank","blank"];
var x = array("blank", "blank", "blank”);
var x = {"blank","blank","blank"};
var x = new Array(1:"blank",2:"blank",3:"blank")


What is the value of x? var obj = {}; obj["function"] = 123; x = obj.function;
native Function constructor
123
undefined. Silent failure.
undefined. SyntaxError due to illegal position of a reserved word


Which of the following operators can assign a value to a variable?
All of these
=
%=
+=


In JavaScript, to call a function directly, you use:
function_expression -> ( arguments_if_any )
function_expression { arguments_if_any }
arguments_if_any ( function_expression )
( arguments_if_any ) -> function_expression
function_expression ( arguments_if_any )


How do you assign object properties?
obj(age) = 25 OR obj.age = 25
obj["age"] = 25 OR obj.age = 25
obj.age = 25 OR obj(@"age") = 25


What is the value of x? var x = '1'+2+3;
6
15
"123"
The statement generates an error.


Which of the following is an Error object constructor?
EvalError
All of these
Error
RangeError


var a = {1:'one',2:'two',3:'three'}; var b = Object.keys(a); What's the value of b?
An array with all of the distinct keys from the obj a
An obj with autowired getters and setters for it's key/values
A serialized copy of the obj a
none of the above


How do you assign an anonymous function to a variable?
var anon = new Function () { };
var anon = function() { };
var anon = func() { };
var anon = func({});


How do you find the number with the highest value of x and y?
Math.max(x, y)
ceil(x, y)
max(x, y)
top(x, y)
Math.ceil(x, y)


What is the RegExp object constructor used for?
Match text against regular expressions
Provides access to Windows registry express values
Regulates the expression of variables
Registers experienced functions with the DOM
Switches numerical notation to exponential


Which of these is not a JavaScript statement?
throw
None, these are all valid statements.
continue
break


var data = ["A", "B", "C", "D"]; data.unshift("X"); data.push("Y"); What does data look like?
["A", "B", "C", "X", "D", "Y"]
["X", "Y", "A", "B", "C", "D"]
["X", "A", "B", "C", "D", "Y"]
["A", "B", "C", "D", "X", "Y"]
["Y", "A", "B", "C", "D", "X"]


The _______ operator returns a string that identifies the type of its operand.
TypeOf
typename
Type
typeof
getType


The "exploit" property:
Represents a variable
Is a very important property
Is obsolete
Does not exist in JavaScript


JavaScript is an implementation of the ______ language standard.
VBScript
ActionScript
ECMAScript
HTML


Which has the correct syntax of a ternary operation?
var x = ( y === true ) { "true" : "false" };
var x = y === true ? "true" : "false";
var x = y === true : "true" ? "false";
var x = ( y === true ) : "true" ? "false";


What is the name of the String prototype that appends the given string to the base string and returns the new string?
"x".combine("foo")
"x".match("foo")
"x".add("foo")
"x".concat("foo")
None of these does that and/or such method doesn't exist in javascript!


What will calling the below test function log to console? function test(){ console.log(a); var a = 'hello'; console.log(a); }
ReferenceError: a is not defined
ReferenceError: a is not defined, "hello"
"", "hello"
undefined, "hello"


Functions in javascript are always ..
in the global scope
loops
objects
operators


If a function doesn't explicitly use the "return" operator, what will the return value be when the function is invoked?
null
undefined
false
closure
NaN


Which of the following have special meanings within the language syntax?
Variables
Literals
Reserved words
Identifiers


Given a variable named stringVar with a string value, what does the following do? stringVar.toUpperCase();
Return a copy of stringVar with all letters in uppercase
Return the number of characters in the stringVar variable
Evaluate any string expression in stringVar
Alters stringVar, changes all letters to uppercase


How do you declare a function?
function doSomething() {}
all of these
function=doSomething() {}
function:doSomething() {}


Which of the following is a way to add a new value to the end of an array?
arr[value] = length;
arr.length = value;
arr[arr.length] = value;
arr[arr.length()] = value;


Which of the following is the syntax for an object literal (with no properties)?
nil;
[];
();
{};
object;


What are curly braces ("{" and "}") used for?
Parsing JSON
Defining a class
Block declarations and object literals
Setting attributes
Invoking a function


What is the value of x? var x = 2 + "2";
22
4
"22"
"4"


What is result of the following expression: var a = "test"; console.log(!!a);
SyntaxError
false
true
undefined


Which of the following is not a method in the "JSON" object according to the ECMAScript specification?
JSON.stringify
JSON.fromString
JSON.parse


What is the result? 0 == ""
Error: type mismatch
true
false


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();
5
null
6
undefined
Error thrown when running the code


How can you concatenate multiple strings?
Both of these
'One' + 'Two' + 'Three'
'One'.concat('Two', 'Three')


When writing an object literal, what is used to separate the properties from each other?
a semicolon ";"
a full-stop "."
a colon ":"
a comma ","
an underscore "_"


What is the result of the following statement: 0 == "";
Throws Error, invalid comparison
false
null
true


Every object is linked to a _________ object from which it can inherit properties.
argument
sibling
parent
prototype


What does "2" + 3 + 4 evaluate to?
9
'27'
'234'


Consider this code: var x = ['Hello']; What value will 'x[1]' return?
"Hello"
null
undefined
['Hello']
NULL


var x = "foo"; x = !!x; What is the value of x?
"!!foo"
true
undefined
NaN


Which is an example of (only) an object literal in Javascript?
var obj = { prop1: 'property 1', prop2: 'property 2' };
var obj = [ "property 1", "property 2" ]
var obj = [ {prop1: 'property 1', prop2: 'property2'} ]
var obj = new Object() { this.prop1 = 'property 1'; this.prop2 = 'property 2'; }


What is the value of `x` after the following? var x = "hello"; (function() { x = "goodbye"; }());
undefined. A SyntaxError is thrown
"goodbye"
"hello"


Is there a value type for individual string characters?
No, there is only type "string" for characters.
Yes, accessing a character offset from a (non-empty) string will yield a value of type "char".


split() is a method of which constructors' prototype?
String.prototype
None of these
Number.prototype
Array.prototype


What is the value of x? function foo(y) { var z = 10; z = 7; }; var x = foo("bar");
undefined
7
10
"bar"
null


Math.random() returns..
a random number between 0 and 1
a random number that can be any value
a random number between 0 and 100
a random number between 0 and 1000


How can you get the number of characters in a string ?
"1234567".Length()
"1234567".Length
"1234567".getLength()
"1234567".length
"1234567".length()


What is the result of the following expression? ({"foo": true}).foo;
undefined
4
false
SyntaxError
true


In the loop, "for (first clause; second clause; third clause) { statements; }" What does the second clause represent?
A condition to check at the beginning of each loop cycle
Code to execute once, after the loop has ended
A condition to check at the end of each loop cycle
Code to execute once, before the loop starts


What will invoking `foo` return? function foo() { var x = 10; x = 7; };
7
10
undefined
null
foo


The "this" keyword refers to ...
function currently being executed.
parent object that hosts the current function.
current execution context (could be any value).


Given the following code, what is the value of x? var x = ['foo', 'bar']; x.length = 1;
[]
["foo"]
["bar"]
["foo", "bar', 1]
["foo", "bar"]


'&' Operator is _____
a bitwise operator
an assignment operator
an operator used in conditionals
a displacement bit operator


var x = Math.ceil(10.126); What is the value of x?
An error, because it was called incorrectly
11
10
10.13


The length property of an Array object is always:
equal to the highest index of that object
equal to the number of properties in that object
equal to the highest index of that object + 1


Which fact is true about the keyword "default"?
It does not exist in JavaScript
It branches program logic based on the value of a condition
It catches any case clauses not caught by case statements within a switch statement
It sets up one variable to check against multiple values


Infinity * null will return :
NaN
null
Infinity


What is the value of x after the following statement? var x = 1 == '1';
false
undefined
true
'1'
1


What is the end value of myAddedVar with the following code: var myVar = '5'; var myAddedVar = myVar + 10;
NaN
'510'
15
510
Nothing, the code will result in an error.


Which of the following types does NOT exist in javascript?
number
boolean
object
integer
string


What does null, undefined, "string", 20, true and false have in common?
they are primitive values
they are objects
they are functions
they have the same instance properties


What is the value of x? var x = typeof new String("abc");
object
string
undefined


var y = 3, x = y++; What is the value of x?
3
4
5
2
6


How do you read the first character in a string?
data.charAt(0);
data.slice(1)
data.substr(0);
data.charAt(1);
data.substring(1);


What is the value of x? var x = typeof null;
"object"
"null"
null
undefined


var data = [1, 2, 3, 4, 5, 6]; data.shift(); What does data look like?
[undefined, 2, 3, 4, 5, 6]
[6, 1, 2, 3, 4, 5]
[2, 3, 4, 5, 6]
[undefined, 1, 2, 3, 4, 5]
[1, 2, 3, 4, 5]


What is the type of `null`, according to the `typeof` operator?
"undefined"
"object"
"array"
"null"


How would you iterate over the following object? var my_data = {a: 'Ape', b: 'Banana', c: 'Citronella'};
None of these. One can only iterate over arrays, not objects.
foreach (my_data as key => value) {}
for (var key in my_data) {}
for (var i = 0; i < my_data.length; i++) {}


What character combination is used to alter the order of operations by grouping expressions?
( )
[ ]
< >
{ }


What does this line do? variable++;
Returns a value 1 greater than "variable" without changing its value
Returns an error to the browser
Increments the value of "variable" and returns the new value
Adds the value of "variable" to itself
Increments the value of "variable" but returns the previous value


Which Object method takes a `propertyName` parameter and returns `true` if the object contains an uninherited property with that key?
obj.exists('propertyName');
obj.hasProperty('propertyName');
obj.doesPropertyExist('propertyName');
obj.hasOwnProperty('propertyName');
obj.contains('propertyName');


var a = new Boolean(false); What is (typeof a)?
'false'
'primitive'
'number'
'object'
'boolean'


What's the difference between the "var" keyword and the new "let" keyword which appears in ECMAScript 6 ?
The "let" declares a local value to a block scope whereas the "var" defines a variable more globally
The "let" was introduced only to deal with for() loops because it's faster than a "var" in that case
The "let" allows programmers to do variables assignment by "destructuring"
The "let" is the new "var". It's faster to create and initialize variables in the computer


Does NaN equal itself?
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).


What is the value of x after the following code is executed? var x = 0; x = x++;
1
0


Which of these is not a built-in object constructor?
Time
Date
RegExp
Array


What is the result? "" ? "a" : "b"
""
Error: "" is not a boolean
"b"
"a"


Which of these will invoke a function?
function.exec(...)
function.invoke(...)
function.Apply(...)
function.Execute(...)
function.apply(...)


Given the following code: var myVar = '5'; var myAddedVar = myVar + 10; What is the value of (myAddedVar.constructor === Number)?
true
NaN
Type Error
undefined
false


function b(x, y, a) { arguments[2] = 10; alert(a); } b(1, 2, 3); What is alerted?
2
1
10
3


What is the right way to combine two arrays into a new array? var a = ["a", "b", "c"]; var b = ["d", "e", "f"];
var c = a.push() + b.push();
var c = a.join(b);
var c = a.concat(b);
None of these


Which String prototype method is capable of removing a character from a string?
delete()
remove()
replace()
destroy()


What will happen in the console after executing this code? if ("foo") { console.log("foo" === false); console.log("foo" === true); }
false true
TypeError : Cannot convert to boolean
NaN NaN
false false


What will the expression a === b return after the following? var a = { "foo": "bar" }; var b = { "foo": "bar" };
false
undefined
true
An exception is thrown.


A javascript variable prefixed with a $ is:
only valid within certain javascript libraries
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


What is the difference between using call() and apply() to invoke a function with multiple arguments?
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()
apply() is deprecated in favor of call()


You use the Math.tan( ) method to:
Return the tangent of an angle (in degrees)
Return the tangent of an angle (in gradients)
Return the tangent of an angle (in radians)
Does not exist in JavaScript


What would this code print out? if (new Boolean(false)) console.log("True"); else console.log("False");
True
False


Which two values are logged by the following code? var x = 5; (function () { console.log(x); var x = 10; console.log(x); }());
nothing. Throws ReferenceError: x is not defined
undefined 10
5 10
10 10


An (inner) function enjoys access to the parameters and variables of all the functions it is nested in. This is called:
Prototypal inheritance
Lexical scoping


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?
undefined
null
5
10


var foo = 'Global'; function fun() { log( foo ); var foo = 'Local'; log( foo ); } fun(); What the output of the above to log()?
undefined Local
Global Local
Local Local
Global Global


Which are the different ways to affect the "this" reference in a function?
Direct attribution, e.g. this = x;
Only by invoking a function with the "new" keyword
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.


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"?
for (var i = 0, len = myArray.length; i < len; i++) {}
for (var i = 0; i < myArray.length; i++) {}
var i = 0; for (; i < myArray.length; i++) {}
None of these, they are all valid
for (var i = 0; i < myArray.length; i += 1) {}


What is the difference between the two declaration methods below? var functionOne = function() { /* some code */ } function functionTwo() { /* some code */ }
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.
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


What is the output? var one; var two = null; console.log(one == two, one === two);
true true
Error: one is not defined
false false
true false
false true


Math.Pi returns the mathematical constant of Pi. What standard JavaScript method would truncate Math.Pi to 3.14 ?
Math.Round(Math.Pi)
Math.Pi.toPrecision(2)
Math.Pi.toString("D2")
Math.Pi.toFixed(2)


Which of the following assigned values of x will cause (x == x) to return false?
NaN
0/0
All of the answers
Number("foo")


When reserved words are used as keys in object literals they must be ______?
Prefixed with the @ operator
quoted
This is not possible in javascript
escaped


(function() { 'use strict'; foo = "bar"; })();
It creates a variable named "foo" in the global object (window)
It enables the JavaScript strict mode and creates a variable named "foo" in the global object (window)
It doesn't do anything
It throws an error : foo is not defined
It kills your browser


What is the value of x.length after running this code? x = ["foo"]; x.quux = "Hello"; x[1] = "bar";
Error on last line: index out of bounds
Error on middle line: cannot add properties to Array
2
1
3


What is the result of: function foo() { output( "biz " + bar() ); } bar(); var bar = function() { return "baz"; }
biz bar
foo baz
baz biz
TypeError: Undefined is not a function
biz baz


What does the following return? Number(null);
0
undefined
1
null


Evaluate: "10" - (17).toString()
Throws Javascript error
-7
3
10125


What is the value of x? var x = typeof NaN;
"number"
"double"
"nan"
"integer"
"object"


true + true will return :
true
2
undefined


How does JavaScript interpret numeric constants outside of strict mode?
As hexadecimal if they are preceded by a zero only
As octal if they are preceded by an underscore
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


The expression (typeof NaN === "number") evaluates to:
false
true
Throws an Error


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();
"foo foo "
"foo bar"
"foo bar "
"bar "


Object.keys(x)
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.
returns all properties of x as an array of strings, including non-enumerable properties.


What will be in console after executing this code: console.log(1 + '1' - 1);
1
'1'
'111'
10


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); }
"baz", "fiz@example.com", null
"baz", "fiz@example.com", undefined
"name", "email"
Type Error
"name", "email", "sendmail"


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;
TypeError: Cannot call method 'bar' of undefined
"Hi"
"function () { this.hello = "Hi"; return this; }"
TypeError: Object -- has no method 'bar'
undefined


How can you remove an element from an array and replace it with a new one ?
array.overwrite(...)
array.splice(...)
array.switch(...)
array.split(...)
array.replace(...)


Which of the following is not a reserved word in the language?
and
while
debugger
instanceof


Which operator has highest precedence?
*
+
-
^


Which of the following String prototype method takes a regular expression?
search()
indexOf()
charCodeAt()
All of these


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']?
x.unshift(0);
x.pop();
x.splice(0);
x.splice(0, 1);


What is the value of x? var x = 10/0;
NaN
0
Infinity
Runtime exception


What will: typeof typeof(null) return?
string
null
empty
Number
error


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);
1 1
Error thrown when running the code
2 1
2 2
1 2


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();
James Matt
Matt James
James James
Matt Matt


What will be the result of this expression: void 0
undefined
null
TypeError
SyntaxError


Whats the output of the below : for(var i = 0; i < 10;i++){ setTimeout(function(){console.log(i) }, 10)}
0 1 2 3 4 5 6 7 8 9
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10
Error


What is the value of x? var z = [typeof z, typeof y][0]; var x = typeof typeof z;
"array"
"string"
"object"
"undefined"


Evaluate: undefined + 2
2
undefined
NaN
Type Error


Evaluate: new Boolean(new Boolean(false)).valueOf()
true
(Instance of object Boolean with valueOf false)
undefined
Type Error
false


console.log( typeof [1,2] ) will print out:
array
object
string
number
undefined


function Question() { this.answered = false; } Question.prototype.rightAnswer = 5; console.log( new Question().rightAnswer, Question.rightAnswer ); What gets printed to the console?
5 undefined
undefined undefined
undefined 5
5 5


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))?
Error thrown
(empty)
null
[object Object]
undefined


function foo(){ var tmp = 'one_two_three_four_five'; return tmp.replace('_', '+'); } What does foo() return?
one+two_three_four_five
one_two_three_four_five
one+
one+two+three+four+five
one_


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);
'Nut' and 'Nut'
'Bolt' and 'Bolt'
'Nut' then 'Bolt'
'Bolt' then 'Nut'


What will be the value of result? function foo(bar) { return bar ? bar == foo : foo(foo); } var result = foo();
Function won't work due to incorrect syntax
Function will end up in infinite loop
Value will be null
true
false


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();
x = "I am global x"; y = "I am global y";
The function throws a SyntaxError
x = "Hello from foo"; y = "I am global y";
x = "Hello from foo"; y = "Hello from foo";


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?
var newArray = oldArray;
var newArray = new Array(oldArray);
var newArray = oldArray.slice(0);
var newArray = [oldArray];


Given the following code, what will myFunction(123, false, "test") return? function myFunction(param) { return arguments[1] || param; }
false
"test"
123
true
undefined


var q = null; q++; What is q?
Type Error
null
NaN
1


Math.min() < Math.max(); will return
undefined
false
null
true


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?
"A" "A"
"A" "B"
"B" "B"
"B" undefined
"A" undefined


What is the output of the following? var x = 1; console.log(x++ + ++x + x);
3
4
7
6


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;
"what"
true
undefined
"who"
Nothing, the code throws a syntax error


What does Math.random() do?
Returns a random number more than 0 and less than 1.
Randomly put numbers in descending and ascending order
Randomly selects a number 1-10.
Returns a random number more than 0 up to and including 1.
Returns a random number from and including 0 to less than 1.


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');
{ name: 'Mike', age: '25' }
This code won't run. It throws a SyntaxError.
null
undefined
{ name: 'Mike', age: 25 }


"bar".split().length returns:
3
1
2
throws an error


What value is passed to function "foo" as first argument? foo( +"5" );
5
0
NaN
"5"
"05"


console.log(1 + +"2" + "2")
Error
122
"122"
32


What will this code produce: +new Date()
Unix timestamp in milliseconds (UTC timezone)
The Unix epoch (1970-01-01 00:00:00)
Unix timestamp in milliseconds (Local timezone)
A SyntaxError


function foo() { this = "foo"; } var a = foo(); What will the preceding code produce?
ReferenceError: Invalid left-hand side in assignment
"undefined"
SyntaxError: Unexpected token
undefined
"foo"


What is the value of a after executing the following: var a = [1, 2, 3]; a.splice(1, 2, 3);
[1, 2, 3, 1, 2, 3]
[ ]
[1, 2, 3, 2, 3]
[1, 3]
[1, 2, 3]


Evaluate the following expression: ~-(2 + "2")
22
21
23
true
-22


Math.log(x) returns:
Logarithm base 2 of x.
Logarithm base 8 of x.
Logarithm base 10 of x.
Logarithm base e (Euler's number) of x.


Object("s") instanceof String === "s" instanceof String
false
true


What will the following code, when evaluated, do? var void = function () {};
Create a local variable named "void" but stays undefined due to a SyntaxError.
Throw a SyntaxError
Assign an anonymous function to variable named "void"


Which of the following expressions evaluates to false?
new Boolean('false') == false
new Boolean(0) == 0
new Boolean('true') == true
new Boolean(1) == 1
They're all evaluate to true


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();
1
6
[object]
Error thrown when running the code
5


Which of the following Array prototype method actually modifies the array it's been called on?
concat()
slice()
all of them
splice()


What does the following return? Math.max();
null
-Infinity
Infinity
0


var obj1 = {}; var obj2 = {}; What are the value of the below: !!(obj1 && obj2) (obj1 && obj2)
false true
true {}
true fasle
{} false


What is the value of "x" after the following code runs? var x; x++;
1
Throws a TypeError on the "x++;" statement
0
NaN
undefined


In JavaScript (ES5) Oriented-Object Programming, is it possible to have a member property of a constructor function to a private state ?
No, because JavaScript is not really Object-Oriented and doesn't have the `private` and `static` keywords like others OOP languages
Yes, by creating a local variable inside your constructor. Moreover, this will allow the methods created in the prototype to access this "private-like" property
Yes, by using the `private` keyword before declaring your member property
No, it's actually not possible because every member you will define inside the constructor will be accessible from the outside
Yes, by nesting your constructor function into a IIFE and creating local variables in it


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) {}
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.
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.


Which are the different value types in JavaScript?
boolean, integer, float, string, array, object and null
boolean, number, string, function, object and undefined
boolean, number, date, regexp, array and object
boolean, number, string, function, object, null and undefined


What is the value of x? var a = "abc"; var x = a instanceof String;
true
false


What's the correct syntax for creating a Date object for January 10, 1998?
new Date(1, 10, 1998);
new Date(0, 10, 1998);
new Date(1998, 0, 10);
new Date(1998, 1, 10);


Evaluate: ![]+[]
true
false
undefined
'false'
Syntax Error

No comments:

Post a Comment