Fundamentals Flashcards
Explain Lexicalscoping
Refers to scope which uses location for name resolution. In other words the scope of a reference is determined by the location of the declaration.
What is a Scope
Where a given name can reference a given construct such as a variable.
Explain Hoisting in JavaScript.
Hoisting in JavaScript is a behaviour where declaration are all moved to the top of the current scope. Such as the current script or function.
Thus the ‘use strict’ mode to force you to declare variables before use.
What bugs can result from hoisting?
It moves up declaration but not the initiation so if the variable is used , it can result in a undefined error.
What is not allowed in strict use mode?
Using variables without declaration
Objects are variables too
Using objects without declaring it, it is not allowed.
Deleting a variable ( or objects) is not allowed.
Deleting a function is not allowed.
Duplicating a parameter name is not allowed.
Octal numeric literals not allowed.
Writing to a read-only property is not allowed:
"Use strict"; var objects = {}; Object.defineProperty(objects, "X", { value: 0, writable:false}); Obj.x = 3.14;
Writing to a get-only property is not allowed:
Deleting an undeletable property is not allowed.
The string “eval” cannot be used as a variable:
The string “argument” cannot be used as a variable.
The with statement is not allowed.
For security reasons , eval() is not allowed to create variable in the scope from which it was called:
In function calls like f() , this value was the global object in strict mode , it is now undefined.
What is the key difference between textContent and innerText?
textContentgets the content of all elements, includingand<style>elements. In contrast,innerTextonly shows “human-readable” elements.</style>
What is the purpose of using anonymous functions?
Because all functions are global by default, there is a danger of overwritting previously function This can however be prevented if you make the function local. This is done by encasing code in a function which is is encased in parenthesis and is known as anonymous functions.
What are partial and curry application
What’s the difference?
Partial application is process where only some of its argument s get applied . The partially applied function gets returned for later use.
It fixes one or two argument s inside the return ed function and the return ed function takes the remaining parameters as argument in order to complete the function application.
What is Promise?
A promise object that may produce a single value some time in the future: either a resolved value, or a reason that it’s not resolved.
It is in 3 states fulfilled , rejected or pending. A callback to handle the fullfilled value or the reason for rejection.
What are the applications of bind, calls and apply in function calls?
Use.bind()when you want that function to later be called with a certain context, useful in events. Use.call()or.apply()when you want to invoke the function immediately, with modification of the context.
What happens when pop is used in an empty array?
POP returns undefined.
What is the purpose of push?
Push such as array.push a new value to the end of array.
What is a shift method?
Shift is used to add one element to the start of an array. It will remove the value in first item
.
What is unshift
It will remove the first element in the array and shift the other values to the left.
It will shorten the array length.
What is the purpose of the delete function?
It will remove the value located in similar index provided in the delete argument.
Advice not to use.