JavaScript ECMAScript6 Flashcards

JavaScript ECMAScript6: Functions

1
Q

Define Pure Function

A

Specific value-producing function with no side effect and doesn’t require effects from other codes.

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

Functions have primarily two purposes

A

1) Called for side effect

2) Called for return value

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

Recursive function

A

Function that calls on itself

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

Stack Space

A

When computer stacks runs out of space.

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

Call Stack

A

Place where computer stores context

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

Almost all JavaScript values have properties. What are the two exceptions?

A

Null and Undefined

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

Access properties in JS by __ and __

A

. and [ ]

ex: value.x or value[ ]

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

How is value.x and value[] evaluated differently?

A

When using a dot, the word after the dot is the literal name of the property. When using square brackets, the expression between the brackets is evaluated to get the property name. Whereas value.x fetches the property of value named “x”, value[x] tries to evaluate the expression x and uses the result, converted to a string, as the property name. The elements in an array are stored as the array’s properties, using numbers as property names. Because you can’t use the dot notation with numbers and usually want to use a binding that holds the index anyway, you have to use the bracket notation to get at them.

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

Two ways to call length in array of variable varx

A

varx.length and varx[“length”]

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

What does doh.toUpperCase() do?

A

writes it all in uppercase as in DOH.

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

What does DOh.toLowerCase() do?

A

writes it all in lowercase as in doh.

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

Properties that contain functions is called ______?

A

methods

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

sequence = [5, 23, 67, 2]

sequence.push(4) would do what?

A

add 4 to the end of an array.

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

sequence = [5, 23, 67, 2]

sequence.pop() would do what?

A

remove the last item in the array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
let day1 = {
  squirrel: false,
  events: ["work", "touched tree", "pizza", "running"]
};
console.log(day1.squirrel);
console.log(day1.wolf);

What would the logs print out?

A

false

undefined

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

Braces have two meanings in javascript? What is it?

A

At the start of a statement, they start a block of statements.
In any other position, they describe an object.

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

Reading a property that doesn’t exist will give you the value __________.

A

undefined

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

assign a value to a property expression with the = operator. This will ______ the property’s value if it already existed or _______ a new property on the object if it didn’t.

A

replace

create

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

Inside braces { } how do you separate properties within?

A

separate by ,

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

let anObject = {left: 1, right: 2};

delete anObject.left;
console.log(anObject.left);

console. log(“left” in anObject);
console. log(“right” in anObject);

What does it print out?

A

undefined
false
true

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

what does the ‘in’ operator do?

A

The binary in operator, when applied to a string and an object, tells you whether that object has a property with that name.

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

the most important HTML tag is _______. This tag allows us to include a piece of JavaScript in a document.

A
23
Q

What does document.documentElement do?

A

return the root element of the document

24
Q

Data structure is a _________, when it has branching structure.

A

tree

25
Q

Application nodes may have children, whereas identifiers and values are ______, or nodes without children.

A

leaves

26
Q

What is XML

A

which is a generic data format with an HTML-like syntax.

27
Q

Is there away to create node and add children/attribute?

A

No. Instead, you have to first create it and then add the children and attributes one by one, using side effects.

28
Q

Parent Node

A

would be something like

29
Q

The firstChild and lastChild properties point to the first and last child elements or have the value null for nodes without children.

A

Points to the first child;

points to the last child.

30
Q

In JavaScript, a truthy value is a value that is considered true when evaluated in a Boolean context. All values are truthy unless they are defined as falsy (i.e., except for ___, __, ___, ___, ____, ____.

A

false, 0, “”, null, undefined, and NaN

31
Q

What is OOP

A

Object-oriented programming

32
Q

OOP helps us to achieve the following…

Abstraction:

A

Determining essential features

33
Q

OOP helps us to achieve the following…

Encapsulation:

A

Containing and protecting methods and properties

34
Q

OOP helps us to achieve the following…

Modularity:

A

Breaking down a program into smaller sub-programs

35
Q

clientWidth and clientHeight

A

Give you the size of the space inside the element, ignoring border width.

36
Q

offsetWidth and offsetHeight properties

A

The size and position of an element can be accessed from JavaScript. The properties give you the space the element takes up in pixels.

37
Q

getBoundingClientRect method

A

It returns an object with top, bottom, left, and right properties, indicating the pixel positions of the sides of the element relative to the top left of the screen. If you want them relative to the whole document, you must add the current scroll position, which you can find in the pageXOffset and pageYOffset bindings.

38
Q

A style attribute may contain one or more ___________, which are a property (such as color) followed by a colon and a value (such as green).

A

declarations

39
Q

what does display:none; do?

A

no css will appear for that property.

40
Q

JavaScript code can directly manipulate the style of an element through the______________. This property holds an object that has properties for all possible style properties. The values of these properties are strings, which we can write to in order to change a particular aspect of the element’s style.

A

element’s style property.

41
Q

When multiple rules define a value for the same property, the most recently read rule gets a higher precedence and wins. Styles in a style attribute applied directly to the node have the _____ precedence and always win.

A

highest

42
Q

hierarchy goes to ID _ CLASS

A

>

43
Q

specificity

A

A rule’s specificity is a measure of how precisely it describes matching elements, determined by the number and kind (tag, class, or ID) of element aspects it requires.

44
Q

selector syntax—the notation used in style sheets to determine which elements a set of styles apply to—is that we can use this same mini-language as an effective way to find DOM elements.

A

Query Selectors

45
Q

___________ method, which is defined both on the document object and on element nodes, takes a selector string and returns a NodeList containing all the elements that it matches.

A

querySelectorAll

46
Q

is querySelectorAll live?

A

Unlike methods such as getElementsByTagName, the object returned by querySelectorAll is not live. It won’t change when you change the document. It is still not a real array, though, so you still need to call Array.from if you want to treat it like one.

47
Q

querySelector method (without the All part) works in a similar way. This one is useful if you want a specific, single element. It will return _____________________________.

A

only the first matching element or null when no element matches.

48
Q
Object.keys function.
EX: 
console.log(Object.keys({x: 0, y: 0, z: 2}));
// → ["x", "y", "z"]
A

You give it an object, and it returns an array of strings—the object’s property names.

49
Q

Object.assign function

A

copies all properties from one object into another.

50
Q

numbers, strings, and Booleans, are all ________________.

A

immutable—it is impossible to change values of those types.

51
Q

JSX is a _____________ for JavaScript. It was written to be used with React.

A

syntax extension

52
Q

If a JavaScript file contains JSX code, then that file will have to be _______. That means that before the file reaches a web browser, a JSX _______ will translate any JSX into regular JavaScript.

A

compiled, compiler

53
Q
Here's an example of a \_\_\_\_\_\_\_ :
const h1 = <h1>Hello world</h1>
A

JSX element: