JavaScript Flashcards

1
Q

What is JavaScript?

A

A scripting language for creating dynamic web page content.

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

ecmascript

A

A standard on how a language should work (ex. javascript) and what features it should have.

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

Destructuring

A

a faster way to access data from arrays, objects, and maps by setting each value as new variables.

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

map (array method)

A

map creates a new array by calling a function on every array element. It does not change the original array.

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

spread operator (ES6) (…)

A

allows you to quickly copy all or part of an existing array or object into another array or object using “…”

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

rest operator (…)

A

allows a function to take an indefinite amount of arguments and bundle them in an array. The rest parameter must be placed at the end of the arguments to gather all remaining arguments.

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

preventDefault (method)

A

method that tells the form we’ll handle what happens when a form is submitted. By default, when a form is submitted, the information is sent through a URL.

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

named export vs default export

A

named export must use the same name. For default, you can come up with any name. You can only have one default export per file. example for named export: “export const books …”. example for default export: “export default books”.

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

named import vs default import

A

named import must be the same name. for default export, we can come up with whatever we want. example- for named import: “import {books} from “./books.js””. example for default import “import banana from “./books.js””.

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

synchronous

A

Tasks are completed one after another. JavaScript is synchronous and single-threaded.

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

asynchronous

A

Tasks are completed parallel to one another. This is a lot better performance-wise than synchronous. In JS, async is provided by Events. Async patterns include - callbacks, promises, and async/await.

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

Blocking

A

Blocks the execution. This is synchronous.

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

Non-blocking

A

Does not block the execution of further-operations. This is mainly asynchronous. Non-blocking is more performant than blocking code.

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

event

A

An event is JS interaction with HTML elements. Such as when the page loads, or when a button is clicked.

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

event loop

A

A constantly running process that coordinates the tasks between the call stack and callback queue to achieve concurrency.

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

callback queue

A

A queue that keeps all callback functions ready for execution and executes after the call stack is empty. This operates on the FIFO principle. The callback functions are pushed to the call stack to execute when the event loop finds an empty call stack.

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

callback

A

a function passed as an argument to another function.

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

promise

A

an object that represents the eventual success or failure of an asynchronous task and its resulting value.

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

.then() promise method

A

When the promise is resolved/fulfilled, you can access the data and display the data within this method. It immediately returns an equivalent Promise object, allowing you to chain calls to other promise methods- creating a promise chain.

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

.catch() promise method

A

When a promise is rejected/fails, you can access the error information and display the error information in this method. It immediately returns an equivalent Promise object, allowing you to chain calls to other promise methods- creating a promise chain.

21
Q

.finally() promise method

A

The last stage of the promise is where the promise has “settled”. This is useful when you want to do something when the promise has settled.

22
Q

.all() promise method

A

This takes multiple promises as input and returns a single Promise. The returned promise is fulfilled if all promises are able to be resolved. It rejects when any of the input’s promises rejects, returning the first reject. This runs the inputs in parallel so it is performant.

23
Q

fetch() method

A

Used to request data from a server. The request can be any type of API that returns the data in JSON or XML. It requires one parameter, the URL to request, and returns a promise.

fetch(URL) // api for the get request
.then(response => response.json())
.then(data => console.log(data));

24
Q

async/await

A

async/await allows you to write asynchronous code using the async and await keywords. The async keyword is used to declare a function as asynchronous, while the await keyword is used to pause the execution of a function until a promise is resolved. Async returns a promise.

When setting up async functions, it is good practice to setup try…catch within the function to catch any errors.

25
Q

for (VARIABLE of ITERABLE) {}

A

a statement that loops through the values of an iterable object such as arrays, strings, maps, nodelists, etc.

26
Q

for (KEY in OBJECT) {}

A

a statement that loops through the properties of an object.

27
Q

fetch API

A

Starts the process of fetching a resource from a server. It returns a Promise that resolves to a Response object. This is a modern promise-based replacement for XMLHttpRequest.

28
Q

short-circuit evaluation

A

For Logical Operators (&&, ||). In JavaScript, an expression is evaluated from left to right until there is a confirmed result. If the condition is met before everything is evaluated, the expression will short-circuit and return the result.

Example for &&: “false && true” will return false and the true is never evaluated.

Example for ||: “true || false” will return true and false is never evaluated.

29
Q

closure

A

an inner function always has access to the variables and parameters of the outer function, even after the outer function has returned.

30
Q

When using methods to manipulate data.

A

When using string, array, object, document, etc. methods, you are using methods available on the String, Array, Object, or Document object. When you create a string for example, that string is automatically created as an instance of String (object), allowing you to use the common methods and properties available on it.

31
Q

class

A

a template for creating multiple objects with the same list of properties but different data values saved in it. A class on its own doesn’t do anything, so every instance of the class that is created is performed by the constructor. We pass values to the constructor for any internal state we want to initialize in the new instance. There are no classes in JavaScript, there is only Object. To be more precise, JavaScript is a prototype-based Object Oriented Language, which means it doesn’t have classes, rather it defines behaviors using a constructor function and then reuses it using the prototype.

32
Q

constructor

A

A special function that creates and initializes an object instance of a class. The purpose of a constructor is to create a new object and set values for any existing object properties. To call a constructor, you use the “new” keyword.

33
Q

prototype

A

a mechanism in which javascript objects inherit features from one another. Every object in JS has the built-in hidden property called “prototype”. Prototype is an object itself and will have it’s own prototype, making a “prototype chain”.

34
Q

OOP

A

A design to model a system as a collection of objects, where each object represents some particular aspect of the system. The four principles of OOP are Abstraction, Encapsulation, Inheritance, and Polymorphism.

35
Q

Abstraction (OOP)

A

show only the essential information and hide the implementation details. You cannot create an instance of an Abstract Class.

36
Q

Encapsulation (OOP)

A

Grouping data and functions into one component and limiting access and functionality to the component to keep it secure.

37
Q

Inheritance (OOP)

A

A class or object inherits the attributes and methods of another class or object.

38
Q

Polymorphism (OOP)

A

The ability for a variable, function, or object to take on multiple forms.

39
Q

super (keyword)

A

is used to call the constructor of its parent class to access the parent’s properties and methods.

40
Q

extends (keyword)

A

Used to create a child class of another class (parent).

41
Q

function declaration vs function expression

A

Function declarations are functions with a name. This will add the function to the global scope; so you can call it throughout your code. A function expression is a function without a name, making it an “anonymous function”. This is useful for limiting where the function is available keeping your global scope light. https://www.freecodecamp.org/news/when-to-use-a-function-declarations-vs-a-function-expression-70f15152a0a0/

42
Q

filter() method

A

Creates a new array filled with elements that pass a test provided by a function.

43
Q

switch statement

A

This is used to select one of many code blocks to be executed.
Format:
switch(EXPRESSION) {
case xxxxx:
// code block
break;
case yyyyy:
// code block
break;
default:
// code block. The default keyword specifies code to run if there is no case match.
}

44
Q

“return” statement in a function

A

This means “the function is done running, here is the result you can show to the parent context. No need to read further.”

45
Q

truthy vs falsy values

A

Falsy - false, 0 (zero), “” (empty string), null, undefined, NaN.
Truthy - All other values, including objects and arrays.

46
Q

! (operator)

A

The ! operator is a logical operator that negates a boolean value. It is equivalent to the not operator in other programming languages.

Example:
if(!false) {
console.log(true);
}

47
Q

Set (object)

A

A collection of unique values.
Example:
new Set([“a”, “a”, “b”, “c”])
//output: Set(3){‘a’, ‘b’, ‘c’}

48
Q

FormData API

A

provides a way to construct a set of key/value pairs representing form fields and their values, which can be sent using the fetch() or XMLHttpRequest.send() method.