Jeopardy Flashcards
What are tenets of functional programming?
- Functional purity - no side-effects, output derived only from input
- Simple functions
- First class functions (functions as variables)
- Higher order functions (functions that return functions or accept functions as arguments)
What is a closure, and how/why would you use one?
- A closure is a function that maintains a reference to its outer scope.
- These are useful in high order functions.
What are the reference data types in JavaScript?
- Object. Just object.
What is the difference between ‘null’ and ‘undefined’
- Undefined has no value
- Null is explicitly set to an empty value
What are the primitive data types in JavaScript?
- Boolean
- Null
- Undefined
- Number
- String
- Symbol (new in ECMAScript 2015)
- Everything that is not a primitive data type is an object
What is the difference between a primitive data type and a reference data type?
- Primitive data types have a fixed amount of memory that they take up
- A reference data type is made up of references to other variables and does not take up a fixed amount of memory
- Primitive types include booleans or integers
- Reference types include arrays
Explain hoisting
- Hoisting is JavaScript’s method of moving declarations to the top of the current scope before the code in the rest of the scope executes
- Makes the function available everywhere in the scope
- To avoid bugs, always declare all variables at the beginning of every scope.
What creates scope in JavaScript?
- There’s global and function scope in ES5. In ES2015 there’s also block scope.
Name 2 or more ways to define a global variable in JavaScript
- Assign in the top level scope
- Leave the ‘var’ off and assign it to the ‘window’
How does inheritance work in JavaScript?
- Inheritance in JavaScript is prototypal.
- Objects are linked to other object instances via prototypes
Explain how prototypal inheritance works
- Every JavaScript object has a prototype property (empty by default), and you attach properties and methods on this prototype property when you want to implement inheritance.
- By adding methods and properties to a prototype, you make those methods and properties available later on.
What is the difference between ‘==’ and ‘===’ in JavaScript?
- ‘==’ (type coercison) checks for equality of value, while ‘===’ checks for equality of both value and data type.
What is async in JavaScript?
- Async is short for “asynchronous”
- Asynchronous code takes statements outside of the main program flow, allowing the code after the asynchronous call to be executed immediately without waiting.
- This allows multiple, independent tasks to be executed without slowing down the UI.
Explain the difference between synchronous and asynchronous functions.
- Synchronous functions must be executed in order. The first queued function must be completed before the second one is.
- Asynchronous functions are executed immediately, without waiting for other functions to execute or resolve.
What is event loop?
- The event loop listens for queued up messages and adds instructions to the call stack
What does the ‘this’ refer to in Javascript
- The first value passed to call() or apply()
- The value that was binded to the function
- The calling object
- The global scope
What is a data type?
- A classification of data which tells the compiler or interpreter how the programmer intends to use the data.