-
How do you write a conditional statement for executing some code if
i
is equal to 5?if (i==5)
if i=5
if i=5 then
if i==5 then
-
What is an array?
- A set of variables stored in one value
- A set of several commands
- A set of values stored in one variable
- A set of several scripts
-
How to declare a variable?
abc = ...
andvar abc = ...
- Only
abc = ...
- Only
var abc = ...
- With neither of these
-
What is result of next line of code?
typeof null
Answer:
null
object
undefined
-
Which of the following function no exist for string?
- reverse
- replace
- substring
- concat
-
When executed, what value will be alerted to the screen?
function() { var a = 10; if (a > 5) { a = 7; } alert(a); }
Answer:
- 7
- 10
null
undefined
-
What would be the value alerted by this function?
function() { if (true) { var a = 5; } alert(a); }
Answer:
- 0
- 5
null
undefined
-
Assuming I call these functions in order, what value gets alerted?
var a = 5; function first() { a = 6; } function second() { alert(a); }
Answer:
- 5
- 6
null
undefined
-
There are now two variables with the same name, a. Which one does Javascript pick?
var a = 5; function() { var a = 7; alert(a); }
Answer: * 5 * 7
-
When executed, this will pop up three alerts. In order, what are they?
var a = 6; function test() { var a = 7; function again() { var a = 8; alert(a); // First } again(); alert(a); // Second } test(); alert(a); // Third
Answer: * 6; 7; 8 * 7; 6; 8 * 8; 7; 6 * 8; 6; 7
-
What's alerted to the screen?
function getFunc() { var a = 7; return function(b) { alert(a+b); } } var f = getFunc(); f(5);
Answer:
* 5
* 7
* 12
* null
-
JavaScript has Math library which can be used like this:
Math.max(8,9,10) // result is 10
. If I provide an array with certain values then how would you find the max value for that array.a = [1,2,3]; //write you code below
-
In the following example, what is foo aliased to?
(function(foo) { // What is 'foo' aliased to? })(this);
Answer:
* undefined
* global object (window)
* null
* this
-
What is the result of next line of code?
"b,ab,sb,".search(/b,/)
Answer:
* -1
* 0
* 3
* undefined
-
What will be alerted?
var f = new Booleand(false); if (f) { alert(f); }
Answer:
* nothing
* undefined
* false
* true
-
Implement the bubble sort.
-
Why do these yield different results?
'1' + 2 + 3 ; // Equals '123' 3 + 2 + '1'; // Equals '51' 3 + 2 + 1 ; // Equals 6
-
Describe how variable hoisting works, and how to avoid bugs that may arise from it.
-
How do these differ?
function foo() {} // versus var foo = function() {};
-
Explain how to determine if a variable is an array or an object.
-
In one line of code, how you would make a copy of an array?
-
What does this snippet of code do?
var foo = bar ? bar : 0;
-
When might you write something like this, and what is it shorthand for?
foo && foo.bar();
-
How do
parseInt
and parseFloat differ? When would you use a number'stoFixed()
method? In what instance might the following code snippet actually make sense to use?var my_number = my_string - 0;
-
Write a function wich finds all the phone numbers in text (> 10000 chars) and replaces them with the name of the country. If number starts with +380 replace by Ukraine, +7 - Russia, +1 - USA, other - N/A.