Javascript Español Flashcards
¿Cuál es la diferencia entre variables undefined y variables undeclared?
- Una variable undeclared es aquella que no se ha declarado usando var. Variables no existen.
- Una variable es undefined cuando se llama a una variable que no ha sido definida. Variables existen pero no tienen nada asignado a ellas.
- Null es una variable que ha sido definida usando un valor null. Ex var NullVar = null;
¿Qué es un closure, cuando y porqué, usarías uno?
Funciones encapsuladas dentro de otras, que tienen acceso a las variables de la función contenedora. Es cualquier función que permanece disponible aún después que la función externa haya sido retornada.
Is when a function remember its lexical scope even when the function is executed outside that lexical scope.
Qué es This en Javascript?
At the time of execution of every function, JavaScript engine sets a property to the function called this which refer to the current execution context. this is always refer to an object and depends on how function is called.
There are 7 different cases where the value of this varies.
1 - In the global context or inside a function this refers to the window object.
2- Inside IIFE (immediate invoking function) if you use “use strict”, value of this is undefined. To pass access window inside IIFE with “use strict”, you have to pass this.
3 - While executing a function in the context of an object, the object becomes the value of this
4 - Inside a setTimeout function, the value of this is the window object.
5 - If you use a constructor (by using new keyword) to create an object, the value of this will refer to the newly created object.
6 - You can set the value of this to any arbitrary object by passing the object as the first parameter of bind, call or apply
7 - For DOM event handler, value of this would be the element that fired the event
Mencione al menos 5 patrones de diseño en Javascript
Constructor, Module, Singleton, Prototype, Factory.
¿Cuál es la diferencia entre .call y .apply?
Call and apply, both takes the value of this as first parameter. However, call takes a collection of arguments after first parameter whereas apply use an array of arguments as second parameter.
¿Podés explicar el uso de Function.prototype.bind?
bind allows you to borrow a method and set the value of this without calling the function. It simply returns an exact copy of the function with new value of this. You can reuse the same function with new value of this without harming the old one.
Example:
var rachel = {name: ‘Rachel Green’, total: 1500};
var rachelFeeDeductor = monica.deductMonthlyFee.bind(rachel, 200);
rachelFeeDeductor(); //”Rachel Green remaining balance is 1300”
rachelFeeDeductor(); //”Rachel Green remaining balance is 1100”
Cómo valido en un if un tipo de dato undefined?
if (typeof nombrevariable === ‘undefined’){
}
¿Podés explicar en qué consiste el “hoisting”?
All variables are declared at the top of any given function scope whether you like it or not (includes function declarations).
¿Podés hablar sobre “event bubbling”?
Events propagate up to the next element is called bubbling.
Explica “event delegation”
Event delegation is registering an event from a parent node will deletes to their child’s node.
Diferencia entre =, == y === ?
Double equals == checks for equality, triple equals checks for equality and type