Javascript Flashcards

1
Q

difference between let, var, const

A

var is global and function scoped, it can be re-declared and re-assigned

let is block-scoped, it will only be accessible within the block it was declared in, we cannot re-declare it but we can re-assign it

const must be declared with value as it cannot be re-assigned, const allows you to change properties of its value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is responsive design

A

Responsive design is an approach to web page creation that makes use of flexible layouts, flexible images and cascading style sheet media queries.

The goal of this is to have web pages that detect users devices and screen sizes and adapt the layout accordingly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is restful API

A

REST stands for REpresentational State Transfer

REST is just a pattern for making API’s

Any API that is created in a REST pattern is a RESTful API

Every restful API should be able to use CRUD operations, create read update and delete with HTTP requests POST, GET, PUT, DELETE

EXTRA :
Architectural Constraints of RESTful API: There are six architectural constraints which makes any web service are listed below:

Uniform Interface
Stateless
Cacheable
Client-Server
Layered System
Code on Demand
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the difference between REST API and RESTful API?

A

REST is just an architectural pattern for designing restful API’s.

RESTful API is an API that follows this said pattern.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the point of RESTful API?

A

With API’s following one set architectural pattern, we can allow API’s to communicate with different programming languages and help web applications which rely on restful API’s to reside in different environments

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is closure?

A

Closures in JS allow us to have functions that hold private variables

Closure means, that when JavaScript runs your code, it looks for all variables in your functions, and if it sees a variable in a function that has no declaration (- let, const) inside of it, but in an outer scope (where the function is nested in) it “locks” the value for that variable inside that given

Famous closure example:

for( var i = 0; i < 3; i++) {
const log = () => {
console.log(i)
}
setTimeout(log,100)
 }

we would usually expect this function to print a console log of I every 100miliseconds
the output should be 0,1,2

But because the variable i is called with var, it’s hoisted to global scope and the for loop runs fully first before the log function is called, so it prints 3,3,3

With the variable called with let, we block scope it and it works properly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a promise?

A

A promise is an eventual completion of an asynchronous operation and its resulting value

A promise acts as a proxy for a value that isnt known when the promise is created

Promises allow us to work with async operations as though they are synchronous

Promises are either pending, fulfilled or rejected

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a callback?

A

A callback is simply a function passed as an argument to another function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is asynchronous programming and why is it important in JavaScript?

A

Asynchronous programming makes it possible to express waiting for long-running actions without freezing the program during these actions. JavaScript environments typically implement this style of programming using callbacks, functions that are called when the actions complete.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to compare objects?

A

if we know both objects are in the same order of keys but we want to check if the values are the same we can stringify both and compare with ===

we can check shallow equality by getting list of properties using Object.keys() then comparing each values, we can return true if they are all the same or false if they arent or are not of same length

if compared objects have nested objects then we have to do deep equality check by triggering a recursive call to check when property is a nested object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is hoisting?

A

JavaScript Hoisting refers to the process whereby the interpreter appears to move the declaration of functions, variables or classes to the top of their scope, prior to execution of the code.

Hoisting allows functions to be safely used in code before they are declared.

Variable and class declarations are also hoisted, so they too can be referenced before they are declared. Note that doing so can lead to unexpected errors, and is not generally recommended.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is apply, call and bind?

A

bind() - allows us to call a function but binding its ‘this’ value to another objects ‘this’

call(), apply() - allows us to call a function and explicitly state which ‘this’ to reference to while also allowing other arguments to be passed

the call method does not make a copy of the function it is being called on

call and apply are the same its just that apply asks for an array of arguments after ‘this’

var logPokemon = pokemonName.bind(pokemon); // creates new object and binds pokemon. ‘this’ of pokemon === pokemon now
pokemonName.call(pokemon,’sushi’, ‘algorithms’); // Pika Chu loves sushi and algorithms
pokemonName.apply(pokemon,[‘sushi’, ‘algorithms’]); // Pika Chu loves sushi and algorithms

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What’s the difference between a variable that is: null, undefined or undeclared? How would you go about checking for any of these states?

A

null means the value points to no object, it is treated as a falsy for boolean operations, it is a js primitive value, null represents the intentional absence of any object value

undefined property indicates that a variable has not been assigned a value

undeclared is any variable that hasnt been assigned with let var or const - will throw a reference error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

what is higher order function?

A

a higher order function is a function that receives functions as arguments and/or returns functions as output

For example, Array.prototype.map, Array.prototype.filter and Array.prototype.reduce are some of the Higher-Order functions built into the language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what different between == and ===?

A

In summary; “==” abstract operator compares the values and then returns true or false. “===” strict operator not only checks the values but also the types of variables. If the values are not of the same type, “===” operator returns false because it does not do the necessary type conversions like the “==” operator does before it compares the equality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly