Frontend and Javascript Trivia Flashcards

1
Q

How does prototypal inheritance work in JS?

A

All JS objects have a prototype property

Objects Linked To Other Objects (OLOO): If an object doesn’t have the property you’re trying to access, JS engine will traverse the prototype chain until it finds the property

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

How do you write testable components?

A

Creating single purpose DRY components

Writing semantic HTML/CSS

  1. Using the appropriate tags to accurately reflect what the component contains
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Object Oriented Programming

A

Description

  • Examples: Prototypes, OLOOs (objects linked to other objects)
  • Imperative (inheritance) programming: set of instructions for the computer operations
  • Let’s say we already have a class that defines an Animal, and now we want to make a Duck. It is an animal, but it needs to be able to fly and quack.
  • In inheritance world, Duck extends Animal and adds the ability to fly/quack. Now those behaviors are tightly coupled with each other.

Pros

  • As code evolves, easily extend new functionality by creating new classes which extends existing classes
  • Existing classes can be left alone

Cons

  • Shared state may lead to side effects: different variables/things competing for the same resources
  • Highly OOP codebase can be extremely resistant to change: and very brittle compared to an equivalent FP codebase.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Functional Programming

A

Description

  • Examples: closures, first class functions, lambdas (anon functions)
  • Declarative (compositional) programming: concentrate on what to do, letting underlying functions take care of how (i.e. makeSorted() is declarative)
  • In composition world, you isolate behaviors, and can give a class superpowers by adding it in like so canQuack(canFly(Animal))
  • This reduced the amount of coupling that occurs and makes it easier to reuse behaviors. You can make a Pilot with canFly(Person) (see image for React version).

Pros

  • Avoids shared state, mutable data and side effects
  • Encourage function purity: self contained and stateless
  • Easier to test b/c can be tested in isolation with typical

Cons

  • Can be harder to read
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

DNS (Domain name system)

A

The way to map URL string (www.google.com) to IP Addresses

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

Compile time vs. Run time

A

Compile time:

  • Interprets higher level language and converts it to machine language (binary language) executable code
  • Things like:
    • syntax parser
    • fixed expression evaluation

Run time:

  • Executes compiled code
  • Whatever the compiler cannot do (due to lack of information) will be done at run-time
    • values depending on variables / user input
    • accessing current time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Breadth First Search

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

Fail Fast Principle

A

You want to catch bugs earlier leading to fewer defects in production code because…

  • compile/build time errors still compile
    • syntax errors
    • data type errors
  • run time errors will crash the consumer
    • logical errors
    • cannot import file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What do you expect to happen here?

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

Classical Inheritance vs. Prototypal Inheritance

A

JavaScript is a class-free, object-oriented language, and as such, it uses prototypal inheritance instead of classical inheritance

Classical Inheritance:

  • instances inherit from classes (Java / C++)
  • create tight coupling or hierarchies/taxonomies
  • class Student { constructor(name) }
  • cannot invoke instance methods on class definition:
    • class Student { constructor(name) this.name=name;}
    • let student = new Student(‘Sally’)
    • right: student.name // Sally
    • wrong: Student.name

Prototypal Inheritance:

  • instances inherit directly from other objects
  • Object.create() / Object.assign()
  • Objects Linking to Other Objects (OLOO): All JS objects have a private prototype property which holds a link to another object (recursive).
  • When trying to access a property of an object, the property will not only be sought on the object but on the prototype chain until either a property with a matching name is found or the end of the prototype chain is reached
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Depth First Search

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

What is rendering?

A

Parse HTML & CSS (construct DOM tree):

  1. Parse HTML => DOM Tree
  2. Parse CSS => Styling rules

Render Tree (RT): Combine both into a data structure called Render Tree aka a Frame Tree

Layout of Render Tree: position the elements (i.e. when floating to the left, it’ll put the element on the left)

Paint the Render Tree: Actual operation of drawing the graphics and painting it onto the screen (visual output)

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

How does the DOM traverse its nodes?

A

Depth First Search

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

What is a ReSTful API?

A
  • REpresentational State Transfer.
  • Uses standard HTTP (Hyper Text Transfer Protocol) commands to perform commands (get, post, put, delete) or exchange data with a service over a network
  • Supports multiple technologies for data transfer such as text, xml, json, image etc.
  • No contract defined between server and client, so loosely coupled implementation.
  • Principles
    • Client-server: Separate UI concerns from data storage concerns to improve portability of UI across multiple platforms
    • Stateless: Request form client to server must contain all information necessary to understand request. Cannot store any context on server and session state is kept on client
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
A

Rendering

Reduce render-blocking requests

  • load 3rd party styles with link tag in HTML instead of with @import in JS
  • load “above the fold” critical CSS first
    • ​​load critical CSS in the head tag above HTML
    • load non-critical CSS in the script tag below HTML

Server-side render non-interactive content

  • Good for Blog posts: server sends HTML (additional JS will needed to be “painted”) and blog posts don’t usually have interaction logic (JS) so it can render right away especially if the response is already cached.

Requests

More CDNs: if you want to increase speed, then decrease the space between your servers and the user

Reuse server connections to speed up requests

Have the backend resize images before sending over the requested size to the frontend

  • ​prevents unnecessarily transmitting large files
  • prevents frontend from resizing images first before rendering

Have service worker check for cached request and skip the network

  • ​if cache has request, respond with cachedResponse otherwise, make request

​Javascript:

Shorter prototype chains: JS uses prototypal inheritance model and lookup time for properties that are high up on the prototype chain (or non-existent properties) will traverse the entire prototype chain

Reuse already loaded data: If you’re going from “all jobs page” to “edit jobs page”, persist the state between page transitions so you don’t have to fetch for data again

  • ​​if “jobs” are edited often, only show the read-only data while fetching the updated data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What do you expect?

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

Function Assignment/Expression: var myFunction = function () {}; (hoisted to top last)

overrides

Variable Assignment: var myName = ‘Sally’; (hoisted to top third)

which overrides

Function Declaration: function myName () {}; (hoisted to top second)

which overrides

Variable Declaration: var myName; (hoisted to top first)

18
Q

“By Value” data types

A

Primitives

  • String
  • Number
  • Boolean
  • null
  • undefined
19
Q

“By Reference” data type

A

Objects:

  • Objects
  • Array
  • Function
20
Q

What is Webpack?

A

Open source JS module bundler

Transforms frontend assets like HTML, CSS and images (if loaders are configured)

Input: modules/dependencies

Output: static assets representing these modules

21
Q

What do you expect to happen?

A

1 is logged (explanation)

22
Q

What is coersion?

A
23
Q

What are meta tags?

A

metadata stuff (see picture)

24
Q

What is Scope in JavaScript?

A
  • Where a variable is available in your code
  • Each function gets its own scope
  • Reference to outer environment: If scope is nested within another scope, code in the innermost scope can access variables from either scope
25
Q

What is SQL injection?

A
26
Q

Why and when should I use Webpack?

A
27
Q

What is Cross-Site Scripting (XSS)?

A
28
Q

When to use the different function instantiation types:

  • function() {}
  • class
  • () => {}
A
29
Q

Explain Function.prototoype.bind

A
30
Q

Classical Function Expressions vs. ES6 Arrow Function

A

Classical Function Expressions/Declarations

  • this: is bound to different values based on the context in which it is called/invoked (CURRENT this)
  • if you add a function/method to a native prototype, it will receive the _this_ from the context it was invoked
  • constructuable and callable

ES6 Arrow Function

  • this: is lexically bound which means it uses the this from the env the arrow func is defined i.e. where it’s contained (ORIGINAL this)
  • if you add a function/method to a native prototype (i.e. String.prototype), this = window NOT the context it was invoked
  • only callable
  • do not use for: Object methods, Prototype methods, Callbacks with dynamic context
    • do not use for: anything involving this, arguments, or new
31
Q

What do you expect?

A

When func is called/invoked, the context is now the Window object and loses reference to the count property

32
A

Add1:

const a timer is created and immediately awaited (2s)

when that’s done…

const b timer is created and immediately awaited (2s)

only when both are done (4s) will it log the sum // 60

Add2:

const _p_a_ timer is created (0s)

const p_b timer is created (0s)

then…

p_a and p_b are both awaited at the same time (2s)

both are done at the same time which will then log // 60

Sequence of Ops:

  1. a is created and awaited (time = 0)
  2. a_p and a_b are created (time = 0)
  3. a_p and a_b are awaited concurrently (time = 0)
  4. a is finished so now b can be created and awaited (time = 2)
  5. a_p and a_b finishes at same time and add2 logs // 60 (time = 2)
  6. b is finished so add1 can now log // 60 (time = 4)
33
Q

Javascript Event Loop

A

Browser includes:

  • JS runtime (v8 engine): callstack
  • native webApis: items pushed to queue like setTimeout
  • rendering engine

Event (callback) loop: routinely checks if call/execution stack is empty, if TRUE: process events in event queue by pushing it into the callstack

34
Q

Execution (Call) Context

A

Creation phase: when hoisting happens

  • hoisting: set aside memory space for vars and functions and sets to undefined
  • includes: var declarations, func decs, var assignments, func assignments

Execution phase: runs code line by line and assigns variable values

Do not confuse setting to undefined (first pass) with setting to actual value (second pass)

With every function call, a new execution context and closure (variable environment) are created with specific variable values (state) that are stored in-memory to be referenced later.

35
Q

Uncaught ReferenceError vs. undefined

A

ReferenceError: variable is not in memory and not defined

undefined: variable is in memery and not defined

36
Q

var vs. let vs. const — What do you expect?

A
37
Q

var vs. let — What do you expect to happen?

A

The let statement declares a block scope local variable

38
Q

What happens when you type “google.com” in your browser?

A
  1. Computer => DNS
  • checks cache, localhost, then DNS
  • gives URL, gets IP Address
  1. DNS => Server (at IP Address)
  2. Server => Computer

https://www.youtube.com/watch?v=DuSURHrZG6I

39
Q

Internet Protocol Suite

A

The Internet protocol suite provides end-to-end data communication specifying how data should be packetized, addressed, transmitted, routed, and received. This functionality is organized into four abstraction layers, which classify all related protocols according to the scope of networking involved. From lowest to highest, the layers are…

  • link layer - containing communication methods for data that remains within a single network segment (link);
  • internet layer - providing internetworking between independent networks
  • transport layer - handling host-to-host communication
  • application layer - providing process-to-process data exchange for applications.

https://en.wikipedia.org/wiki/Internet_protocol_suite

41
Q

HTTP

A

Hypertext Transfer Protocol (HTTP) is an application-layer protocol for transmitting hypermedia documents, such as HTML. It was designed for communication between web browsers and web servers.