Interview Wiki Javascript/React/Frontend Flashcards

1
Q

What is a potential pitfall with using typeof bar === “object” to determine if bar is an object? How can this pitfall be avoided?

A

Although typeof bar === “object” is a reliable way of checking if bar is an object, the surprising gotcha in JavaScript is that null is also considered an object!

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

What is the significance of, and reason for, wrapping the entire content of a JavaScript source file in a function block?

A

This is an increasingly common practice, employed by many popular JavaScript libraries (jQuery, Node.js, etc.). This technique creates a closure around the entire contents of the file which, perhaps most importantly, creates a private namespace and thereby helps avoid potential name clashes between different JavaScript modules and libraries.

Another feature of this technique is to allow for an easily referenceable (presumably shorter) alias for a global variable. This is often used, for example, in jQuery plugins. jQuery allows you to disable the $ reference to the jQuery namespace, using jQuery.noConflict(). If this has been done, your code can still use $ employing this closure technique, as follows: (function($) { /* jQuery plugin code referencing $ */ } )(jQuery);

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

What is the significance, and what are the benefits, of including ‘use strict’ at the beginning of a JavaScript source file?

A

The short and most important answer here is that use strict is a way to voluntarily enforce stricter parsing and error handling on your JavaScript code at runtime. Code errors that would otherwise have been ignored or would have failed silently will now generate errors or throw exceptions. In general, it is a good practice.

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

What is NaN? What is its type? How can you reliably test if a value is equal to NaN?

A

The NaN property represents a value that is “not a number”. This special value results from an operation that could not be performed either because one of the operands was non-numeric (e.g., “abc” / 4), or because the result of the operation is non-numeric (e.g., an attempt to divide by zero).

While this seems straightforward enough, there are a couple of somewhat surprising characteristics of NaN that can result in hair-pulling bugs if one is not aware of them.

For one thing, although NaN means “not a number”, its type is, believe it or not, Number:

console.log(typeof NaN === “number”); // logs “true”
Additionally, NaN compared to anything – even itself! – is false:

console.log(NaN === NaN); // logs “false”

A semi-reliable way to test whether a number is equal to NaN is with the built-in function isNaN(), but even using isNaN() is an imperfect solution.

A better solution would either be to use value !== value, which would only produce true if the value is equal to NaN. Also, ES6 offers a new Number.isNaN() function, which is a different and more reliable than the old global isNaN() function.

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

What is a “closure” in JavaScript?

A

A closure is an inner function that has access to the variables in the outer (enclosing) function’s scope chain. The closure has access to variables in three scopes; specifically: (1) variable in its own scope, (2) variables in the enclosing function’s scope, and (3) global variables.

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

What are undeclared and undefined variables?

A

Undeclared variables are those that do not exist in a program and are not declared. If the program tries to read the value of an undeclared variable, then a runtime error is encountered.

Undefined variables are those that are declared in the program but have not been given any value. If the program tries to read the value of an undefined variable, an undefined value is returned.

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

What is negative infinity?

A

Negative Infinity is a number in JavaScript which can be derived by dividing negative number by zero.

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

What is ‘this’ keyword in JavaScript?

A

‘This’ keyword refers to the object from where it was called.

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

What is the function of the delete operator?

A

The functionality of delete operator is used to delete all variables and objects in a program but it cannot delete variables declared with VAR keyword.

This answer is not complete. Please see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete when assessing candidates’ answers.

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

What are the major features of React?

A

It uses VirtualDOM instead of the real DOM because real DOM manipulations are expensive in terms of performance.
Supports server-side rendering.
Follows Unidirectional data flow or data binding.
Uses reusable/composable UI components to develop the view.

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

What is JSX?

A

JSX is an XML-like syntax extension to ECMAScript (the acronym stands for JavaScript XML). Basically it just provides syntactic sugar for the React.createElement() function, giving us expressiveness of JavaScript along with HTML-like template syntax.

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

Why you can’t update props in React?

A

he React philosophy is that props should be immutable and top-down. This means that a parent can send any prop values to a child, but the child can’t modify received props.

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

What are the React lifecycle functions?

A

Read about ‘em all here.

Underlined = very common, candidate should definitely know.

–Mounting:–

constructor()
static getDerivedStateFromProps()
render()
componentDidMount()

–Updating:–

static getDerivedStateFromProps()
shouldComponentUpdate()
render()
getSnapshotBeforeUpdate()
componentDidUpdate()

–Unmounting:–

componentWillUnmount()

-Error Handling:-

static getDerivedStateFromError()
componentDidCatch()

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

(CSS-Beginner) What are the different types of CSS selectors? Explain how CSS specificity is calculated.

A

Answer: Type, class, and ID (others include attribute, universal, and pseudo-classes). Numerically, an inline style is worth 1000, IDs are 100, classes are 10, and types are 1. Knowing the exact numbers is not crucial – you could also explain this by noting the order in which each selector overrides the others.

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

(CSS-Beginner) Explain the difference between inline elements and block-level elements. Name some elements that default to each type.

A

No answer from wiki provided

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

(CSS-Intermediate) Explain the difference between inline and inline-block.

A

Inline elements:

respect left & right margins and padding, but not top & bottom
cannot have a width and height set
allow other elements to sit to their left and right.
Block elements:

respect all of those
force a line break after the block element
Inline-block elements:

allow other elements to sit to their left and right
respect top & bottom margins and padding
respect height and width

17
Q

(CSS-Intermediate) Explain CSS sprites, and how you would implement them.

A

Bonus: how will HTTP/2 affect this? Answer: This will be a bad practice.

18
Q

(CSS-Intermediate) What’s the difference between a relative, fixed, absolute, and statically positioned element?

A

No answer from wiki provided

19
Q

(CSS-Advanced) Tell me about some principles you’ve learned that that help lead to maintainable CSS.

A

This is open-ended, but they may mention some CSS methodologies such as OOCSS, SMACSS, BEM, or SUIT.

20
Q

(javaScript - Beginner) I’m in a function, and I have two declarations: x = 2 and var x = 2. What’s the difference between these two declarations?

A

global scope, function scope.

21
Q

(javaScript - Intermediate) Explain how closures work.

A

no wiki answer provided

22
Q

(javaScript - Intermediate) Explain how event bubbling works.

A

no wiki answer provided

23
Q

(javaScript - Intermediate) Explain event delegation. What property in the event object allows this to work?

A

no wiki answer provided

24
Q

(javaScript - Intermediate) What’s the result of 0 == false, and why?

A

Answer: true.

25
Q

(javaScript - Intermediate) Explain hoisting.

A

no wiki answer provided

26
Q

(javaScript - Intermediate) What techniques have you used to organize or modularize your code?

A

no wiki answer provided

27
Q

Tell me about how call and apply work.

A

Call a function with a given value for “this.” It’s ok if they get the two confused (apply takes an array, and call takes arguments).

28
Q

Explain the bind method (If they didn’t get the call and apply question - skip this).

A

Create a new function that uses a given value for “this.”

29
Q

Explain how the Array map function works.

A

Create a new array with the results of calling a provided function on every element in the array.

30
Q

Explain how prototypal inheritance works in JavaScript.

A

no wiki answer provided

31
Q

How can you identify the value of “this” in a function?

A

no wiki answer provided

32
Q

What’s your favorite ES6 (ES2015) feature?

A

no wiki answer provided

33
Q

If you could change anything about the JavaScript language, what would it be?

A

no wiki answer provided

34
Q

Whiteboard “FizzBuzz tests” (check basic JS coding skills)
How would you make each of these work?

add(2, 5); // 7
add(2)(5); // 7

A
35
Q

Define a spacify function that separates each character with a space:

spacify(‘hello world’); // ‘h e l l o w o r l d’

A

Simplest answer:

function spacify(str) {
return str.split(‘’).join(‘ ‘);
}
Could also use a for loop.