Todo Flashcards

1
Q

Dynamic Typing

A

You don´t tell the engine what type of data a variable holds, it figures it out while your code is running. Variables can hold different types of values because it`s all figured out during execution

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

What keyword exist to tell the engine what kind of data you intend to put inside a variable?

A

There is NO keyword

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

What is a primitive Type?

A

A type of data that represents a single value

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

An object is a primitive type?, and why?

A

not, because an object is a collection of name / value pairs

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

How many primitive types exist in JS

A

6 primitive types

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

Name the 6 primitive types in JS

A

undefinednullbooleannumberstringsymbol

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

Describe the primitive type: Undefined

A

Represents lack of existence, its what the JS engine sets variables to initially and it will stay undefined unless you set the variable to have a value.

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

Describe the primitive type: Nulland when its useful

A

represents lack of existence (you can set a variable to this).its useful when you want to represent that something doesn´t exist, that the variable has no value(set a variable to nothing).

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

Describe the primitive type: Boolean

A

Either true or false, just one of two values

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

Describe the primitive type: NumberExist other numeric types in JS?

A

There’s only one numeric type.Its a floating poing number (theres always some decimals)

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

Describe the primitive type: StringWhat we use to define a string?

A

A sequence of characters (both ‘’ and “” can be used)

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

Describe the primitive type: Symbol

A

It`s defined in ES6

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

What is an operator?

A

It`s a special function that is syntactically (written) differently. Generally operators take 2 parameters and return one result.

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

How did the JS engine that this was my intent to add 3 and 4?var a = 3 + 4;console.log(a); // result: 7

A

The syntax parser saw the plus(+) sign and added these 2 numbers.The plus sign is an operator, it’s actually a function.

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

What is the name of the notation that the JS engine provide to deal with operators.

A

Inflix notation

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

What it means “inflix notation”

A

Inflix mean that the function name, the operator, sits between the 2 parameters.

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

When we type these operators, +, -, >, How these operators works?

A

These operators are a special type of functions, that the parameters between the operators are being passed to those functions and a value is being returnedInside those functions is prewritten code, for you that the JS language provides to do or run, or invoke these functions.

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

What is operators precedence?

A

It´s which operator function gets called first, functions are called in order of precedence (HIGHER precedence wins)

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

What is operator associativity?

A

What order operator functiosn get called in: left-to-right or right-to-left, and this means when the operator functions have the same precedence

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

What is the purpose of operator precedence and associativity?

A

help us determine which function run first and so does associativity.

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

When comes into play operator associativity?

A

Associativity comes into play when two or more operators have the same precedence

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

What is coercion?

A

It´s converting a value from one type to another.

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

Why coercion happens in JS?

A

Because it´s dynamically typed

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

How coercion and operators relate, and what we need to understand from this?

A

We understand that operators are functions, so they`re running code, and coercion is part of that process of calling that function, coercion happens because JS it´s dynamically typed.

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

Explain why this code returns Trueconsole.log( 3 < 2 < 1 );

A

Thanks to operators precedence and associativity, we now that the “< operator” is called 2 times so it has the same precedence, so associativity comes into place. The associativity is left-to-right.”3 < 2” is called first, and the result is a boolean of “false”. Thanks to coercion, “false” is converted to the number of 0, so “0 < 1” is TRUE

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

When coercion reprensents a problema that might be hard to debug? and why?

A

When we are comparing two valueswith the “==” operator, and one of the values is not from the same typeThe double equal operator “==” will try to coerce one of the values to the other type

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

How can we solve, the comparision problem with the “==” double equal operator, knowing that coercion could happend

A

We can use the “===” triple equal operator “strict equality”, that compares if they are the same type and the value. If they are not the same type, it will return FALSE

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

Why this is all falseBoolean(undefined) // falseBoolean(null) // falseBoolean(“”) // false

A

Because of coercion, all things that imply the lack of existence, they convert to false.

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

Describe one way to use coercion to our advantage?

A

Using an “if” statement

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

Why the use of an “if” statement, can helps us to use coercion to our advantange?

A

Because whatever we put inside the parentheses of an if statement, it will attempt to convert or coerce to a Boolean

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

When can we face a problem using an “if” statement and coercion to our advantange…

A

When we are going to coerce the value of 0, becauseBoolean(0) –> False0 is not lack of existence, maybe it’s a valid value

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

How can we solve the problem using coercion, in an “if” statement, if we know that there is any chance that the value to coerce is going to be a 0?

A

doing:var a; // it goes to the interner and returns somethingif(a || a === 0) { }Thanks to operator precedence and associativity, we know that it’s going to compare first if “a”, so if a has a value it will coerce to TRUE, either if is 0 and is FALSE, the || operator will do “a === 0”, and result in TRU

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

How can we use coercion if we want to have a default value in a function and we don´t have passed any parameters to it?and when it could be a problem, with what value?

A

We can use the operator ||name = name || “default name”thanks to operator precedence “||” is going to be run before “=”, and “||” will return the first value that is TRUE, so if name has not existence it means it`s FALSE, then it will return “default name” and will be assigned to “name”We still need to be careful if name = 0;

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

What values can hold an Object ? and how they are called?

A

A primitivethat is called a propertyAn object that is called a property alsoFunctions that are called methods

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

An object have reference in memory to their peorperties and methods?

A

YES

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

How is important to think about an Object as…(When we talk about how it´s an object in memory)

A

As sitting in memory, and then having references to other things sitting in memory that are connected to it, so it knows where its different properties and methods are, that is: primitives, objects and functions. (properties and methods)

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

How can we access those slots in memory, those properties and methods of an object?and how are their names(of the operators)?

A

With 2 operators:the dot operator . also called member accessthe computed memeber access operator [ ]

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

What does the computed member access operator [ ] ?and help me to remember what an operator is, under the hood?

A

Remember, an operator is a function.The computed member operator, takes two parameters and it’s associativity is left-to-rightto the left it takes the object, and inside the [ ] it takes the property or method

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

What does the dot . operator do?

A

It’s a fnction and when used after an object it takes two parameters, the object that you’re looking at and the name of the property.It takes the object(on the left) and on the right the string that represents the name of the value that you are looking for

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

What is the other name of the dot . operator?

A

It´s also called Member Access

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

Why the dot . operator is called Member Access

A

Because members being members of the object, These are looking for members of the object, the pieces, the methods, and the properties

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

How can we create an object with object literals

A

using curly braces { }

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

What is inside the curly braces { } how is it treated, how many lines of code?

A

It´s treated as one line of code

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

When it gets really powerful to use object literals?

A

Because we can create objects on the flyFor example, on passing parameters to a function, as an object literal

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

Let´s pass some object as a parameter to this function, how can we imagine this.function greet(person) { console.log(“Hi ” + person.firstname);}

A

We can call the greet funciton, and create an object on the flygreet({ firstname:‘Tony’, lastname:‘Garcia’});

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

What “think” the JS engine when itsees:greet({ firstname:‘Tony’, lastname:‘Garcia’});

A

it says:”oh, you are calling a function, and oh, what are you gonna pass to it? Well, I just saw curly braces { } so I know you´re creating an object right here at this moment of execution and passing it, it`d be no different than passing anything else like a number or a string”

47
Q

It´s true to say that “Wherever i want I can create an object as I go, and I can use an object wherever I use any variable”?

A

YES

48
Q

What is a Namespace?

A

A container for variables and functions, typically to keep variables and functions with the same name separate.

49
Q

JS have namespaces? and why?

A

NO, because of the nature of how objects works inJS, we don´t need it as a feature

50
Q

How can we fake namespaces, for preventing collisions like this one:var greet = “hello!”;var greet = “hola!;console.log(greet) // hola!

A

by creating an object that will be the container for our properties and methods and the things we want to use. The object it won’t really have any other functionality, and that’s okayvar english = { greetings: { basic:‘Hello’ }}console.log(english.greetings.basic);

51
Q

What is the idea of using objects as faking namespaces? and why?

A

We need to containe variables, methods, functions, properties from the global namespaces.Because someone else might have written or even that we´ve written code in the global namespace and forgotten about.

52
Q

What it means JSON, and what is JSON

A

Javascript object notation.It´s just a string of data

53
Q

In a JSON format, how properties needs to be wrapped?

A

in quotes “ “

54
Q

JSON is a part of JS?

A

No

55
Q

Imagine a JSON format file, with two properties, how it will look?

A

{“firstname”: “Mary”,“isAProgrammer”: true}

56
Q

How can we set a valid object literal in JS to a JSON format?

A

using the JSON.stringify() method

57
Q

How can we pass a valid JSONstring of data, to an Object in JS?

A

using JSON.parse() method

58
Q

1) Anything that is JSON valid is also valid JS object literal syntax?2) All object literal syntax is valid JSON?

A

1) YES2) NO

59
Q

What is the meaning of “first class functions”

A

Everything you can do with other types you can do with functions. Assign them to variables, pass them around, create them on the fly

60
Q

In JS, functions are objects?

A

YES

61
Q

Does a function object resides in memory?

A

Yes, it resides in memory

62
Q

Does a function object, has all the features of a normal object and has some other special properties?

A

YEs

63
Q

Can you attach properties and methods to a function? and why?

A

Yes, you can.Because it´s just an object

64
Q

Does function objects has some hidden special properties?

A

YES

65
Q

What are the hidden properties of a function object?

A

the code propertyand the name property (it could also be anonymous)

66
Q

What does the code property of a function object do or have?

A

it has the actual lines of code that you´ve written.So the code that you write gets placed into a special property of the function object.

67
Q

The code property of a function object, we can say that its like a …. of the function object

A

We can sey that its like a PROPERTY that you´re adding on to it

68
Q

What is the special thing about the “code property” of a function object?

A

It´s that is invocable, meaning that you can run the code that it´s in that property.

69
Q

What is the special thing that makes total sense in JS that happens when in a function object, you invoke the “code property” with the ()

A

It´s the execution context creation phase and execution happens.

70
Q

The code inside a function, it´s just a ….

A

The mental model of knowing that the code inside a function, it´s just a property, a “code property” like other property, that it´s invocable via (), meaning that the “code property” it´s going to be run.

71
Q

What is an expression?

A

a unit of code that results in a value, it doesn´t have to save to a variable

72
Q

What is the difference between a function statement and a function expression?

A

a function statement just do worka function expression or any expression in JS ends up creating a value and that value doesn´t necessarily have to save inside a variable

73
Q

function expressions are hosited?

A

no, it just hoisted the variable

74
Q

What happens in the execution phase when it gets to a function statement

A

function statement: the function is already in memory, so it doen´t do anything “oh yeah, there´s a function there, it keeps going”

75
Q

What happens in the execution phase whe it gets into afunction expression?

A

the statement results in an object being created, it returns an object essentially, so it´s an expression, it results in a value, the value being a new function object

76
Q

When we pass values “by value” what do we mean:ej:var a = 3;var b = a;

A

We are creating a new address in memory, a new location in memory, and a copy of the value from “a” is setting in “b”It´s a completely new value

77
Q

When we pass a value “by reference” what do we mean?

A

We are setting a reference to the value, the new variable has a reference to the same spot in memory that the original variable has

78
Q

When we talk about “by value” and “by reference”Which one apply to whicn onePrimitives and objects types

A

Primitives, are passed by valueObjects, and function objects(a special type of object) are passed by reference

79
Q

What happens when we use the keyword “this” inside a function statement, to where “this” will point

A

It will point to the Global Object

80
Q

What happens when we use the keyword “this” inside a function expression, to where “this” will point

A

It will point to the Global Window Object

81
Q

What happens when we use the keyword “this” inside an object, to where “this” will point?

A

to the object itself, the object that is containing “this”

82
Q

What happens when we have the “this” keyword inside a function expression, inside a method of an object, to where it will point?, and why?var c = { name:‘The c object’, log: function() { console.log(this); var setName = function(newName) { this.name = newName; } setName(“updated again”); console.log(this); // added the name property into the Window Object }}

A

It will point to the Global ObjectWhy? The internal function setName(), when its execution context was created, the “this” keyword points to the global object.

83
Q

What can we do when we have the “this” keyword inside a function, that it´s inside a method of an object, how can we resolve the porlbme that the “this” keyword is pointing to the global object?

A

We know that an object are going to be set equal by reference, so we can create a new variable and reference it to the same location in memory as the “this” keywordvar c = { name:‘The c object’, log: function() { var self = this; console.log(self); var setName = function(newName) { self.name = newName; } setName(“updated again”); console.log(self); // }}

84
Q

Any internal function inside a method in an object, that is using the keyword “this” will be pointing to the Global Object, or to the object itself?

A

It will be poiting to the global object

85
Q

What is an array?

A

Its a collection of anything, it can holds many things

86
Q

How can we declare an array using array literals

A

var a = [1, 2, 3];

87
Q

Complete the sentenceBecause JS is …… ….. we can put anything into an array

A

dynamically typed

88
Q

Function expressions are like a kind of a function literal were we are creating a function on the fly?

A

YES

89
Q

How can we trick the syntax parser to see a function statement like a function expression?

A

We have to make sure that the first thing that the syntax parser see, its not the word function, so we need to wrap the function with ( ) the grouping operator

90
Q

Why when we wrap a function statement with ( ) the grouping operator, the syntax parser doesn´t give an error?

A

Because everything that goes into the grouping operator ( ) it´s an expression. We only use ( ) with expressions.

91
Q

What “think” the syntax parser when it sees a funciton statement inside the grouping operator ( )

A

it must me an expression, it must be a function expression, the programmer its creating this function “on the fly”.

92
Q

How can we make a IIFE immediately function expression?

A

We need to wrap a function statement with the grouping operator ( ), and since a function, it´s a special type of object in JS, we can invoke the code property with (), so we must use the invoke sytanx at the end of the grouping operator(function(name) { return‘Hello‘ + name;})();

93
Q

What is the purpose of having an IIFE?

A

To protect our code from other outside codeTo prevent us to put something accidentally in the global object

94
Q

How can we pass information from our IIFE into the global object?

A

simply passing around parameters, objects pass by reference, so if we want access to the global object, we just pass the reference to the global object into our function(function(global,name) { var greeting =‘Hello’, global.greeting =“hola”, console.log(greeting +‘‘ + name);})(window,‘John’)); // Hello Johnthat´s the way to have our code, maybe some object in our function that we want to be available everywhere else in our code, we can stick it on the global object.

95
Q

Why we can return a function as a value?

A

Because functions are objects, are first class functions, a special type of object

96
Q

Que es un closure?

A

Los closures son funciones que manejan variables independientes. En otras palabras, la función definida en el closure “recuerda” el entorno en el que se ha creado.—Es crear una función dentro de otra función para que cuando cuando busque variables, estas sean independientes porque las busca en su propia referencia externa, porque cada función (la primera en ejecutarse) creasu propio contexto de ejecución.Nos sirve para tener una “factory function” funciones creadoras de funciones.

97
Q

What is a callback function?

A

A function you give to another function, to be run when the other funciton is finished.So the function you call(invoke) calls back, by calling the function you gave it when finished—- —- —- —-function tellMeWhenDone(callback) { var a = 1000; var b = 2000; callback(); // the callback, it runs the function we give it}tellMeWhenDone(function() { console.log(‘done!’);});tellMeWhenDone(function() { console.log(‘reallydone!’);});

98
Q

What does the bind() method

A

returns a new function(makes a copy of the function, and sets up a new function object with the copy), and sets “this” to whatever object we want.

99
Q

what does call()

A

let me decide what “this” will be, and i can pass arguments to itcall() doesn´t create a new function, it works as if we invoke it

100
Q

what does apply()

A

executes a function, deciding what “this” should point to, the arguments must be passed with an array list

101
Q

What method can we use for doing “Function borrowing”, and give one example

A

call() and apply()For function borrowing, when we want to use a method from one object, on another object!

102
Q

What method can we use when we want to do “function currying”? and why

A

We can use bind() method, because bind creates a new copy, and since its a new copy of the function object, the parameters that we pass sets the permaments values of these parameters when the copy is made!function multiply(a, b) { return a * b;}var multipleByTwo = multiply.bind(this, 2);console.log(multipleByTwo(4)); // 8// The permament value of the second parameters b will be always 2function multiply(b) { var a = 2; return a * b;}

103
Q

What means, function currying?

A

Creating a copy of a function but with some preset parameters

104
Q

To where points “this” in this casefunction asdf() {console.log(this);}

A

To the global windows object.

105
Q

What we need to look at when we have the “this” keyword inside a function or object, to where it its pointig to?Cómo nos podemos dar cuenta hacia donde apunta “this” cuando estamos invocando una función o metodo que esta usando a la palabra “this”.

A

Podemos fijarnos como es invocada esa funcion / metodoel operador dot . es el que nos va a avisar hacia donde apunta, si tiene algo a su izquierda, es ese objeto, si se invoca sin punto, generalmente es el objecto global window

106
Q

Describe what is “this”(to where it points) in the following scenarios:1) Inside a method of an object2) Inside a function statement3) Inside a function expression4) An internal function, that it´s located inside a method of an object

A

This points to:1) The object itself, the object that is calling the method2) global variable window3) global variable window4) points to the global variable( lot of people think this is a bug)

107
Q

What is one of the purposes of making a function factory?

A

To have variables inside and secure in a closure

108
Q

How can we create a function factory that is going to be using always the parameters that we pass?What could happend if we pass variables as parameters to a function that return another function.

A

Using a function factory, and returning a functionWhen we return a function from a function, we are creating a closure.When the returning function executes it creates itw own execution context, and its outer reference will point to the execution context that was created when invoking this function that returned this function (That´s a closure)

109
Q

What is the key to understandin closures?Every time you call a function…

A

it gets itw own execution context,, and any function created inside of it will point (outer reference) to that execution context.It wil point to the memory space, as if those other execution context hadn´t disappeared.It knows which ones to point to properly, where these inner functions were created and when.

110
Q

For what are useful the function factories?

A

To stop passing parameters that could be used as defaultvar greetEnglish = makeGreeting(‘en’) // makeGreeting returns a functiongreetEnglish(‘Bruno’, ‘De Angeli’); // greetEnglish has the returned funciton with the language set by default, tx to closures.

111
Q

How creates a closure, the JS or us?

A

TheJS creates the clousure, its a feature, we are just taking advantage of it.

112
Q

When the execution context that was actually running finish his execution and goes away…1) What happens to that memory space where the variables and functions created inside of it live?2) And how this relate to closure and “function factories”

A

1) It still continues in memory…2) It relate to closure in the way that if we are returning a function from a function, and the first function execution context is gone, and we execute the second execution context(from the function that was returned from the first function) we still has a reference to the memory of the first function. We can still go down the scope chain and find it-We can say that the execution context has closed IN its outer variables, the variables that it would normally have reference to anyway, even though those execution context are goneThat´s a closure, and that´s why we can make function factories

113
Q

What is the meaning of free variables, and when it comes natural to get them?

A

its natural to get them when we are inside a closure.It is a variable that is outside a function, but that you have access to.