JS Concepts Flashcards

JS Tricky parts

1
Q

CLOSURE

A

The ability for inner functions to remember variables defined in outer functions, long after the outer function has returned. Useful for encapsulating logic and private variables.

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

IIFE

A

Immediately Invoked Function Expression
A function which is invoked immediately. Used for encapsulating variables and functions in a scope, preventing them from being manipulated or accessed from outside.

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

PROTOTYPE

A

Prototypes are mechanisms that help JavaScript objects inherit features from one another.

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

The new keyword

A

The new keyword does four things:
1. Creates an empty object
2. Sets the keyword ‘this’ to be that object
3. Returns the object - return this
4. Creates a link to the object’s prototype

MDN: The new operator lets developers create an instance of a user-defined object type or of one of the built-in objects types that has a constructor function.

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

This keyword

A
  1. Global context: which is window
  2. The function context:
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Prototypical Inheritance

A

Prototypical inheritance is a key feature of JavaScript that allows objects to inherit properties and methods from other objects. In JavaScript, each object has an internal property called [[Prototype]] that points to another object, known as its prototype. If a property or method is not found on an object, JavaScript looks up the prototype chain until it finds the property or until the end of the chain is reached.

How Prototypical Inheritance Works:
Prototype Chain:

Every object in JavaScript has a prototype, which is itself an object, forming a chain of prototypes.
The chain is traversed during property or method lookups.
Object Creation:

Objects can be created using constructor functions, object literals, or other means.
prototype Property:

Functions have a prototype property, which is used as the prototype for objects created by that function.
Object.create() Method:

The Object.create() method is used to create a new object with a specified prototype.
**********
// Constructor function
function Animal(name) {
this.name = name;
}

// Adding a method to the prototype
Animal.prototype.sayHello = function() {
console.log(Hello, I'm ${this.name});
};

// Creating objects using the constructor
const cat = new Animal(‘Cat’);
const dog = new Animal(‘Dog’);

cat.sayHello(); // Output: Hello, I’m Cat
dog.sayHello(); // Output: Hello, I’m Dog

// Prototypical inheritance
function Dog(name, breed) {
// Call the parent constructor
Animal.call(this, name);
this.breed = breed;
}

// Inherit from Animal’s prototype
Dog.prototype = Object.create(Animal.prototype);

// Adding a method specific to Dog
Dog.prototype.bark = function() {
console.log(‘Woof!’);
};

const germanShepherd = new Dog(‘Rex’, ‘German Shepherd’);
germanShepherd.sayHello(); // Output: Hello, I’m Rex
germanShepherd.bark(); // Output: Woof!

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

Object Methods

A
  • Object.keys(obj): returns an array containing the names of all properties of an object.
    • Object.values(obj): returns an array containing the keys
    • Object.hasOwnProperty(prop): returns a boolean indicating if the object has a property with the specified name.
    • Object.entries(obj): returns an array of arrays where each inner array has the key and value pair
    • Delete object.property
    • TO change a key, you can follow the example:
      Person.firstname = person.name
      Delete person.name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Set Methods

A
  • Add(value): adds a new element to the set.
    • Has(value): checks if the value is in the set.
    • Delete(value): deletes an element from set
    • Clear(): removes all the elements from the set.
    • Size: returns the numbers of elements in a set.
    • forEach():
      method invokes (calls) a function for each Set element.

CHADSF

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

Map methods

A
  • Set(key, value): sets the value of a specific key in the map.
    • Get(key): Returns the value associated with a specificied key in the map.
    • Has(key): returns a boolean indicating whether a Map contains a key.
    • Delete(key): removes the related key and value and returns a boolean indicating whether entry was deleted.
    • Clear(): removes all the entries from the Map.
    • Size: returns the number of entries.
    • Entries(): returns a new iterator object that ccontains an array of [key, value] for each entry in the map.
    • Keys()
    • Values()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Higher Order Function

A

A higher-order function is a function that takes one or more functions as arguments, or returns a function as its result.

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