Last active
January 4, 2016 01:19
-
-
Save nixsticks/8547184 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What does the following code evaluate to? | |
var first_name = function (name) { | |
return name; | |
} | |
first_name("bob"); | |
-------------------------------------------------- | |
"bob" | |
-------------------------------------------------- | |
What does the following code evaluate to? | |
function add(x, y) { | |
return x + y; | |
} | |
add(2, 3); | |
-------------------------------------------------- | |
5 | |
-------------------------------------------------- | |
Create an anonymous function and assign it to the variable full_name. The function should take two arguments, first_name and last_name, and return the two strings concatenated. | |
-------------------------------------------------- | |
var full_name = function (first_name, last_name) { | |
return first_name + " " + last_name; | |
} | |
-------------------------------------------------- | |
What does the following code print to the console? | |
function square (x) { | |
return(x * x); | |
} | |
console.log(square(5)); | |
-------------------------------------------------- | |
25 | |
-------------------------------------------------- | |
What does the following code print to the console? | |
function square (x) { return(x * x) }; | |
function cube (x) { | |
return(x * square(x)); | |
} | |
console.log(cube(2)); | |
-------------------------------------------------- | |
8 | |
-------------------------------------------------- | |
Invoke the my_fun() function. | |
function my_fun() { return "I am having fun" }; | |
-------------------------------------------------- | |
my_fun(); | |
-------------------------------------------------- | |
What does the following code print to the console? | |
var what = function () { return "HI!!!!" }; | |
console.log(typeof(what)); | |
-------------------------------------------------- | |
"function" | |
-------------------------------------------------- | |
What does the following code print to the console? | |
var max_value = function(array) { | |
var result = array[0]; | |
for (var i = 0; i < array.length; i++) { | |
if (array[i] > result) { | |
result = array[i]; | |
}; | |
} | |
return result; | |
} | |
console.log(max_value([1, 50, 2])); | |
-------------------------------------------------- | |
50 | |
-------------------------------------------------- | |
What does the following code print to the console? | |
var arr = ["boy", 42, 23, function () { return "gotta catch 'em all, Pokemon!" }, 56]; | |
console.log(arr[3]()); | |
-------------------------------------------------- | |
"gotta catch 'em all, Pokemon!" | |
-------------------------------------------------- | |
What is the code to invoke the following function? | |
function kesha() { | |
return "Your love is my drug"; | |
} | |
-------------------------------------------------- | |
kesha(); | |
-------------------------------------------------- | |
What does the following code print to the console? | |
var lambchop = function () { | |
return "This is the song that never ends"; | |
} | |
console.log(lambchop()); | |
-------------------------------------------------- | |
"This is the song that never ends" | |
-------------------------------------------------- | |
What does the following code print to the console? | |
function doctor_name (last_name) { | |
return "Dr. " + last_name | |
} | |
console.log(doctor_name()); | |
-------------------------------------------------- | |
"Dr. undefined" | |
-------------------------------------------------- | |
What does the following code print to the console? | |
function dwelling(name) { | |
if (typeof(name) != "string") { throw "ArgumentError" }; | |
return name + " cave"; | |
} | |
console.log(dwelling(42)); | |
-------------------------------------------------- | |
"ArgumentError" | |
-------------------------------------------------- | |
What does the following code print to the console? | |
function add(x, y) { | |
return(x + y); | |
} | |
console.log(add(1, 2, 3, 4, 10, 20)); | |
-------------------------------------------------- | |
3 | |
-------------------------------------------------- | |
What does the following function return? | |
function args () { | |
return arguments; | |
} | |
console.log(args(8, 7, 6, 5, 4)); | |
-------------------------------------------------- | |
[8, 7, 6, 5, 4] | |
-------------------------------------------------- | |
What does the following code print to the console? | |
function lamp() { | |
var my_special_variable = "I am special"; | |
} | |
console.log(my_special_variable); | |
-------------------------------------------------- | |
ReferenceError | |
-------------------------------------------------- | |
What does the following code print to the console? | |
function book() { | |
good_book = "Slaughterhouse Five"; | |
} | |
console.log(good_book); | |
-------------------------------------------------- | |
"Slaughterhouse Five" //this should be undefined though because they never call the book function. | |
-------------------------------------------------- | |
num = 23; | |
function evil () { | |
num += 5; | |
} | |
evil(); | |
console.log(num); | |
-------------------------------------------------- | |
28 | |
-------------------------------------------------- | |
Create a function called min_value() that accepts an array of numbers as an argument and returns the smallest value from the array. | |
-------------------------------------------------- | |
function min_value(array) { | |
var sorted = array.sort(function(a,b) { | |
return a - b; | |
}); | |
return sorted[0]; | |
} | |
-------------------------------------------------- | |
Invoke the song() function. | |
function song () { | |
return "Mary had a little lamb"; | |
} | |
-------------------------------------------------- | |
song(); | |
-------------------------------------------------- | |
Define a function called add_numbers() that adds two numbers and throws an error if the arguments supplied to the function are not numbers. | |
-------------------------------------------------- | |
function add_numbers(i, j) { | |
if (typeof i !== "number" || typeof j !== "number") { | |
throw "ArgumentError"; | |
} | |
else { | |
return i + j; | |
} | |
} | |
-------------------------------------------------- | |
Invoke the bad_hairday() function in the following array. | |
arr = [0, "nice", function bad_hairday () { return "YOLO" }]; | |
-------------------------------------------------- | |
arr[2](); | |
-------------------------------------------------- | |
Define an anonymous function and assign it to the your_name variable. The function should return "Snoop Dogg". | |
-------------------------------------------------- | |
var your_name = function() { | |
return "Snoop Dogg"; | |
} | |
-------------------------------------------------- | |
What does the following code print to the console? | |
var result; | |
if (undefined) { | |
result = function () { return "blah blah blah"; }(); | |
} else { | |
result = function () { return "meow meow meow"; }(); | |
} | |
console.log(result); | |
-------------------------------------------------- | |
"meow meow meow" | |
-------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment