- Triple Add Function: tripleAdd(10)(20)(30) // returns total of all 3 numbers added together
- What is an IIFE, and why are they used?: Immediately invoked function expression. It declares a function and then calls it immediately. Used to take advantage of the local scope of variables inside the function. Example in Repl.it
- Source code guessing: Given some source code, guess what will happen when the various buttons are pushed.
- Closures: What is a closure? Code out an example of a closure. My Answer: a closure defines a function in a specific scope so that it explicitly has access to that scope. Instructor’s Answer: A closure is an inner function that has access to the scope of an enclosed function.
- Hoisting: Describe what variable and function hoisting is and how it works. Answer: Variables and functions are hoisted to the top of the scope in which they are declared. Essentially, you can’t call or log out a variable or function before it is defined. Also, bear in mind that
constare block scoped, not function or global scoped.
- Scope and ‘self’ question: Look at the given code and guess at what is logged out to the console. NOTE: The code explains it all.
- == vs ===: What is the difference between
==stands for ‘equals’ and tests for abstract equality (doesn’t test for data type), whereas
===stands for ‘strict equals’ and tests for strict equality (tests for data type).
- Log number function: Look at the given source code and determine what will be logged to the console. Answer: It logs as undefined, probably because of the keyword
varbeing used twice. The second
varis function scoped, so
var numis hoisted to the top of the function, but not defined until after the
- Use strict: What does
use strictdo to code, and what are the benefits of using it? Answer: Enforces stricter parsing and error handling in the code. It prevents the use of global variables; enforces that all function parameters must be unique; prevents deleting Object properties that are important. Essentially,
use strictthrows errors when we do bad stuff with our code, informing us early of errors that could throw off our code later.
- Curry function: Given some starter code, curry the function. Answer: Function with multiple parameters should be re-written as multiple, embedded functions with one parameter each.
- Counter function: Write a function that keeps track of how many times it was called and returns the number. Answer in the code.
- Logging X and Y: Looking at the example code, what are the values of
Ywhen they are logged out? Answer is in the code example.
call()method can be used to call a function with an object as an argument. The
apply()method is similar, but it takes an array as an argument.
- Determine ‘list2’: Look at example code, and determine what
list2will contain when it is logged to the console. Then, determine how
list2can refer to
list1without the extra elements added by the
- Singly and doubly invoked functions: create a function (see source code) that can be either singly invoked or doubly invoked. Answer in the code.
- JSON data: Describe what JSON format is. Given source code, delete the data types not permitted in JSON, and replace placeholder text with the corresponding data type, properly formatted as JSON. Answer in the code.
- Order logged out: Given source code, determine in what order the numbers 1, 2, 3, 4 will be logged. Answer in the code.
- Making an object: List and describe three different ways of making an object. Answer in the code.
- Constructor functions: This isn’t a separate question, but, rather, a continuation of notes from the last question. Check it out.
- Type of data types: Given some source code, determine what will be logged out for each
console.logstatement. Answer in the code.
- Bind method: Describe the
bind()function method. How does it work? What parameters does it take? Code out an example of how it is used. Answers: From MDN, “The
bind()method creates a new function that, when called, has its
thiskeyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.” See code example.
- Two Objects: Given source code, determine what is logged out at the bottom. Answer in the code.
- Array constructor: Given source code, determine what is logged out for each of the constructor statements. Answer in the code.
- Array indexOf: Given source code which uses the
indexOf()function, determine what will be logged out to the screen for each
console.log(). Answers in the code.
- Equivalent numbers: Given source code, determine what will be logged out to the console. Answer in the code.
- Objects and strings: Given source code, determine what is logged out. Answer in the code.
- Strings and arrays: Given source code, determine what will be logged out at the bottom. Answers in the code.
- Object properties: Note that this is a very common interview question. Given source code, determine what will be logged out at the bottom. Answers in the code.
- X and Y: Given source code, determine what will be logged out at the bottom. Answers in the code.
- Withdraw from account: Given source code, determine what will be logged out at the bottom. Answers in the code.