Basic_Javascript Flashcards

1
Q

What are four FAQs about JavaScript?

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

What is Javascript?

A

One of the most popular and widely used programming language in the world right now.

It’s growing faster than any other programming languages.

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

What large companies are building full applications around JavaScript right now?

A

Nextflix, Walmart and Paypal

Entire applications around Javascript

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

What is an average salary for a JavaScript developer?

A

You can work as:

Front End (React, Angular)

Backend (Node.js)

Full Stack (MEAN)

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

What can you do with Javascript?

A

We can build many things now.

mobile/web apps

networking apps / chats / video streaming / games

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

What was JavaScript originally designed for doing?

A

For a long time, Javascript was used only for building front end interactive web browsers.

But those days are long gone!

Thanks to huge community support and investment and support by Google, Facebook Javascript has changed.

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

Where was JavaScript originally designed to run?

A

Javascript was originally designed to run only in browsers.

Every browser has a JavaScript engine:

FireFox: SpiderMonkey

Chrome: v8

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

Where does Javascript code run?

A

Browser:

JavaScript Engine

Node:

C++ w/ JavaScript Engine

Both:

Javascript can be run in the browser using the built-in Javascript engine or in Node!

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

What happened in 2009?

A

Ryan Daal

Took the open-source Javascript engine in chrome and embedded it into a C++ program.

Called it Node.js

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

What is node?

A

Node is a C++ program that includes Google’s V8 Javascript engine.

Now we can run Javascript outside of a browser.

We can pass our code to Node for execution.

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

What is ECMA script?

A

ECMA script is just a specification

ECMA is responsible for defining standards

annual release of a specification

ES2015/ES6 defined many new features

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

What is the difference between ECMAScript and JavaScript?

A

JavaScript is a programming language that adheres to the standards provided in ECMAScript.

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

What can we do in Chrome Developer Tools?

A

Run JavaScript.

Every browser has a JavaScript engine

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

What is a good IDE for JavaScript?

A

Visual Studio code - lightweight IDE

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

What else should we install?

A

Node - technically don’t need node to run JavaScript but we use node for installing third-party libraries.

It’s good to have node on your machine!

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

What does ! Tab generate in Visual Studio Code?

A

Boiler plate HTML

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

What is the Live Server extension?

A

A lightweight local server we can use to run JavaScript

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

What does run with Live Server do?

A

It opens our browser and allows us to run our applications!

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

What is best practice for where to put the script section in our HTML page?

A

The best practice is to put the script at the end of the body section after all existing elements.

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

What do we want to explain with our comments?

A

Why’s

How’s

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

What is a statement?

A

A piece of code that expresses an action to be carried out

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

Why is it best practice to put the script after all the elements in the body section?

A
  1. The browser parses HTML file top to bottom - if script is in the head, Browser might get busy executing Javascript code and not be able to render elements on-page.
  2. JavaScript often acts on the elements - If the script is at the end we can be confident all elements have been rendered by the browser. Sometimes third party code requires being placed in the head (this is exception).
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What’s a shortcut to bring the browser developer tools?

A

Option + Command + i

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

What is separation of concerns?

A

Separate HTML (content) from Javascript (behavior)

You don’t want to write it in line with HTML.

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

What is the difference between HTML and JavaScript?

A

HTML is all about content

JavaScript is all about behavior

  • How should your webpage behave?
  • What should happen when we hover over an element? Something pops up, something hidden?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

How do we execute JavaScript code in node?

A

Open the terminal

call node filename.js

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

What is the Integrated Terminal in Visual Studio?

A

Can run JavaScript using node without explicitly opening our terminal.

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

What do we use variables for doing?

A

Storing data temporarily in a computer’s memory

Name of variable - label on data

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

How do we declare a variable?

A

Use the “letkeyword

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

What are variables by default in Javascript?

A

undefined

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

How can we declare a string in Javascript?

A

use single quotes

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

What are the rules for naming variables?

A

Use camelCase

Rules:

Cannot be keywords

Use meaningful names

Cannot start with a number

Cannot contain a space or hyphen

variables are case sensitive

declare each variable on a new line

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

How do we declare a constant in JavaScript?

A

use the “constkeyword

use it as default choice

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

What are the two types in JavaScript?

A

Primitive (Value) Types

Reference Types

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

What are the primitive (value) types in JavaScript?

A

String

Number

Boolean

undefined

null

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

What separates Javascript from other languages?

A

It’s a dynamic language

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

What is the difference between a static and dynamic language?

A

Static:

Declare a variable, the type is set, cannot be changed

Dynamic:

Type can change in runtime

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

What is a dynamic language?

A

Type of variable can change at runtime!

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

How do we clear the console in our browser?

A

Control + L

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

What are all numbers in Javascript?

A

Type number

integer, floating-point, etc. are all type number

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

What type is null?

A

Type object

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

What are the reference types in JavaScript?

A

Objects

Arrays

Functions

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

What is an object?

A

Related variables grouped together

Keys = Properties

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

What is the object literal syntax?

A

Curly braces

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

How can we access an object property?

A

Dot notation (one way)

default choice

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

What is bracket notation?

A

In Javascript, an object is a key-value pair

to access the value can use bracket notation

object [target property] -> value at target displayed

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

What is the second way to access an object’s members?

A

Bracket Notation

Pass a string that determines the name of the property

Use this for unknown selection

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

What are arrays in JavaScript?

A

A data structure used to represent a list of items

Dynamic

Objects and sizes are dynamic

Can store different types in arrays

Can add/remove items

Arrays in JavaScript are Objects

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

What are one of the fundamental building blocks in JavaScript?

A

Functions!

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

What kind of operators do we have in JavaScript?

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

What is an expression?

A

Operations + variables + constants are used to create expressions

expressions are used to create algorithms

Something that produces a value

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

What type of arithmetic operators do we have in JavaScript?

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

How does the increment operator work?

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

How does the decrement operator work?

A

–x (decrement first, then assign)

x– (assign, then decrement)

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

How can we use the assignment operator to increment the value by more than one?

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

What are comparison operators?

A

returns a boolean

===

(three equal signs)

equality

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

What is the strict equality operator?

A

Ensures both operands are of the same type and value

If the two operands are not of equal type

returns false

More precise and accurate

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

What are lose equality operators?

A

Converts both operands to the same type

Checks the value only

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

What is the ternary operator (conditional operator)?

A

Start with the condition

if evaluate true, use first value

if false, use the second value

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

What are logical operators?

A

Operators used to make decisions based on multiple conditions

&& - returns true if BOTH operands are true

|| - returns TRUE if ONE of the operands is true

! - reverses the boolean

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

What can we use logical operators to do in JavaScript?

A

Can use logical operators with non-boolean values!

Extremely powerful

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

How does JavaScript engine interpret non-boolean values in logical operations?

A

falsy or truthy

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

What values are falsy?

A

undefined

null

0

false (boolean)

’ ‘ (empty string)

NaN

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

How does JavaScript engine evaluate non-boolean logical operands?

A

If the value is falsy, treats it as a false

if the value is !falsy, treats it as true

runs normal && ! or || operations

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

What values are truthy?

A

not falsy (below)

undefined

null

0

false (boolean)

’ ‘ (empty string)

NaN

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

What is short-circuiting?

A

JavaScript will stop evaluation

once a truthy value is found

Ex.

false || 1 || 2

returns 1 (truthy)

doesn’t evaluate 2

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

What is the result of this expression?

A

OR operator returns true because ‘1’ is truthy

ternary operator executes first statement “hello

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

What does using the logical OR operator between non-booleans allow us to do?

A

Provide default values

If user selects color, use it

otherwise, provide default color

value is returned

69
Q

What type of conditional statements do we have in JavaScript?

A
70
Q

What is the syntax for if-else statements in JavaScript?

A
71
Q

How can we simplify our if-else statement?

A

Remove curly braces if single statement

72
Q

What are switch statements?

A
73
Q

What does mosh say about switch statements?

A

Outdated, look a bit ugly

Comes down to personal preference

he uses if-else statements

less noise in the code

74
Q

What do loops allow us to do?

A

repeat an action a number of times

75
Q

What kind of loops do we have in JavaScript?

A

Subtle differences in how they start/end

basically do the same thing

76
Q

What is the syntax for a for loop?

A
77
Q

What is a difference between a while loop and a for loop?

A

loop variable is declared externally

For loop, the “ i “ is part of the syntax

while loop, declare “ i “ outside the loop

78
Q

What is the syntax for a while loop?

A

first, the condition is evaluated

if true, statements are executed

if false, loop is terminated

79
Q

What is a do-while loop?

A

Realistically, not used often

first, evaluates the expression

then, checks the condition

80
Q

What do we use the for-in and for-of loops?

A

Iterate over the properties in an object or array

81
Q

How do we iterate the individual properties in an object?

A

forin loop

Use bracket notation to access object properties

bracket notation if the value is calculated at run time

82
Q

What is the syntax to display properties in an object using a for-in loop?

A

Must access properties with bracket notation

pass key as the name of the target property

83
Q

What do we use a for-in loop to do?

A

iterate over the properties of an object

84
Q

What is the for-of loop?

A

ECMASCRIPT 6 released

ideal for iterating over elements in arrays!

85
Q

What are break and continue keywords?

A

keywords that change how loop behaves

1. break - causes javascript engine to jump out of a loop (terminate)

2. continue - causes javascript engine to jump to the beginning of the loop (restarts the loop)

86
Q

Write a function that takes two numbers and returns the max of the two

(Hint: If else)

A
87
Q

How can we make this code cleaner?

(Hint: ternary operator aka conditional operator)

A
88
Q

What is very amateurish and ugly about this code?

A

no need to explicitly return true / false with ternary operator

89
Q

Write code to solve the FizzBuzz algorithm?

(Hint: popular interview question)

A
90
Q

Write a function that checks the speed of a driver

Hint:

speedLimit = 70

every 5 km over speedLimit earns user 1 point

if user gets 12 points, license suspended

A

test a function with different values

91
Q

How can we make this code cleaner?

A

Use the return keyword

remove the else block

92
Q

Write a function that takes a number and counts down displaying the number and whether it is “even” or “odd”.

A
93
Q

How do we clean up this code?

(Hint: conditional operator (ternary operator))

A
94
Q

Write code to count the number of truthy values in an array

(Hint: for..of loop)

A
95
Q

Write code to show the properties of an object if property is a string

(Hint: for in loop, typeof)

A
96
Q

Write a function that adds the multiples of 3 and 5 together between any number

(Hint: for loop)

A
97
Q

What are objects in javaScript?

A

Collections of key, value pairs

highly related variables grouped together

variables

nested objects

functions (that act on variables)

98
Q

What is OOP?

A

A style of programming

A collection of objects that talk to eachother to perform some functionality

99
Q

What’s the problem with object literal syntax?

A

As our applications get large, not best approach

to create a second object, have to repeat code

Soln?

factory functions / constructor function

100
Q

In modern javascript, how can we make this code cleaner?

A
  1. Variables and arguments - if key and value are the same (argument and obj. variable)

can omit the value

Ex. radius: radius vs. radius

  1. method syntax - instead of defining as a key value pair, can define like a function without function keyword

Ex. draw: function () {} vs. draw() { }

101
Q

Why are factory functions a good way to create objects?

A

Allow us to reduce code duplication

if there is a bug, can fix in one place

102
Q

What is the naming convention for constructor functions?

A

NOT camelCase (oneTwoThreeFour)

PascalNotation (OneTwoThreeFour)

103
Q

What are our objects in javascript?

A

Dynamic

Can always add additional properties and methods!

can always remove properties and methods

104
Q

What three things happen when we use the ‘new’ operator?

A

First, creates an empty object

Then, sets ‘this’ to point to object

Finally, returns object

105
Q

What is the key difference between factory functions and constructor functions?

A

Factory functions - call a function that returns a new object, camelNotation

Constructor functions - uses new operator, uses ‘this’ operation, PascalNotation

developers familiar with C or Java prefer constructor functions

Why?

Looks similar to syntax

106
Q

What are functions in JavaScript?

A

Objects!

Confusing

107
Q

What two types of variables do we have in JavaScript?

A

primitives and objects

108
Q

What must we know about primitives vs. objects in regards to copying?

A

primatives are copied by value (independent of one another)

objects are copied by their reference (objects, functions, arrays)

value inside a function is independent of another primative outside of scope

Ex. local parameter inside a function will point to object

109
Q

How can we iterate an object to get all the methods or variables?

(Hint: Objects are not iterable by nature)

A

Use Object.keys - returns an keys as a string array

can iterate array, using for of loop

Use Object.entries ( ) - returns entries as a string array

110
Q

How can we enumerate an object and copy all properties into a new object?

(Hint: Object.assign())

A

Modern JavaScript has Object.assign() method

111
Q

What is a third way to clone an object in JavaScript

(Hint: Spread Operator)

A
112
Q

How is garbage collection handled in JavaScript?

A

memory is automatically allocated to object

when done using, don’t have to re-allocate

JavaScript engine has a garbage collection

that will automatically look for variables that are no longer used

we have no control over this

based on a complex algorithm

runs in the background

113
Q

What is the Math object?

A

Built in object in JavaScript

if you need to use mathemtical calculations in your applications, refer back to this object

114
Q

How many kinds of strings do we have in JavaScript?

A

Two Kinds:

  1. String Primitive - JavaScript will wrap string into a string object if using dot operator
  2. String Object - uses constructor function and the ‘new’ keyword
115
Q

What are some of the String methods?

(Hint: look at String documentation)

A

.length() - gives length of string

.includes()

.startsWith()

.indexOf()

.replace()

.toUpperCase()

.trim()

116
Q

What is escape notation?

(Hint: Strings)

A
117
Q

What are template literals?

(Hint: ` ` )

A

Help us write cleaner code

How?

Using a different character to define string (back tick character)

applications?

Sending emails in applications

Why?

Can format exactly as we want

118
Q

What are the benefits of template literals?

(Hint: back ticks vs. quotes for strings?)

A
  1. Write cleaner code - don’t need escape characters for quotes or formatting, can write strings exactly as you want them displayed without extra noise
  2. Add dynamic fields - use ${ field } as a placeholder to insert a field dynamically!
119
Q

What are Date ( ) objects in JavaScript?

A
120
Q

What are some Date ( ) object methods?

A

.setFullYear ( ) - sets a year

.toDateString() - returns a date string

.toTimeString() - returns time component of date object

.toISOString( ) - standard ISO format, used in web/mobile apps, to transfer dates

121
Q

How do we create an object that has street, city, zipcode fields and a function that displays the contents of the object?

(Hint: factory function, constructor function, for in loop)

A
122
Q

How can we create an address object?

(Hint: factory method, constructor method, literal method)

A
123
Q

How do we check if two objects are equal?

Hint: areEqual( ), areSame ( )

A

Cannot use ’===’

why?

Objects are reference type

JavaScript will check if these two objects have same reference

124
Q

How can we create a blog object?

(Hint: object literal syntax)

A

comments field - is an array of objects

125
Q

How do we create a blog object?

(Hint: constructor function method)

A
126
Q

Use objects to create the price filter in yelp.

(Hint: array of price objects)

A

When looking at a concept:

Imagine, what properties would you put inside an object?

The more you practice this, easier it becomes

127
Q

What are we going to learn in the Arrays section?

A

These concepts are extremely important

esp. when starting out!

Make sure to finish the excercises in this section!

128
Q

How do we add elements to the beginning, end or index in an array?

(Hint: push, unshift, splice)

A
129
Q

How do we find primitives in an array?

(Hint: indexOf, includes, lastIndexOf)

A
130
Q

How to we locate a reference type in an array?

(Hint: find method)

A

Why?

includes method checks references for equality not objects

How?

Pass a predicate to .find (function that takes one argument)

specify a criteria for search in function

131
Q

What are arrow functions?

A

Cleaner ways of passing a callback argument

pass a callback argument without annonymous classes

How?

use =>

( ) if no paraments

single line, remove curly braces

put on same line

132
Q

How do we empty the contents in an array?

(Hint: reassign, set .length to zero, splice, pop)

A
133
Q

How do we combine or slice arrays?

(Hint: concat, slice)

A
134
Q

How can we use a forreach loop in JavaScript?

(Hint: .forEach)

A
135
Q

How can we split and join arrays?

(Hint:.split, .join)

A
136
Q

How do we sort an array of reference type objects?

(Hint: .sort(function))

A
137
Q

How can we sort number array’s in JavaScript?

(Hint: primitive arrays, .sort(), .reverse())

A

Works on primitives - numbers, strings, etc.

DOES NOT work on reference types (Objects, Functions)

138
Q

How can we test every element in an array?

A

.every( Predicate ) checks if every element matches a certain criteria

Ex. allPositive?

139
Q

How can we test for at least one element that matches our criteria in an array?

A

.some(predicate)

These are new methods in JavaScript (.every ( ) .some ( ) ) - older browser’s don’t support these yet!

140
Q

How can we filter an array of primitive values?

(hint: .filter(function))

A
141
Q

How could we create a yelp filter for restaurants that are currently open?

(Hint: filter array of objects by criteria)

A

array of restaurants, filter based on open hours

142
Q

How do we map an each number value in an array to an a cooresponding array of objects?

(Hint: .map(function))

A

Very useful when building real world applications!

Both .filter( ) and .map( ) return a new array!

Don’t modify original array!

These methods are chainable (can call after another in chain)

143
Q

How can we use chaining for filtering and mapping arrays?

(Hint: chaining)

A

the power of chaining these methods!

144
Q

How can we reduce an array?

(Hint: .reduce((reductionResultVariable,

A

reduce method (arrays) -

can reduce all elements into a single value (number, string, object, anything)

145
Q

How can we create a function that converts a number range into an array of numbers based on that range?

(Hint: for loop)

A
146
Q

How can we write the .includes ( ) function that tests each element in an array for matching a value?

(Hint:.some (lambda function))

A
147
Q

How can we write a function that returns an array without a specific set of values present in an input array?

(Hint: for of loop, .includes( ) )

A

returns a new array that excludes a value from input array

148
Q

How can we write an algorithm that moves items in an array?

(Hint:.splice(start, delete, value))

A

.splice(start, delete, add)

cut the element out of the index

paste the element into the offset index

return output

149
Q

How do we write code to countOccurences of a number in an array?

(Hint: for of loop, .reduce ( ) )

A
150
Q

How can we get the max occuring value in an array?

(Hint: reduce array to a single value)

A

.reduce ( )

By default, accumulator will be set to first value in array (if don’t pass init value)

Why?

Want to find largest value, reducing array into a single value

151
Q

How can we write code to display the name property only of movies that are in 2018 with a rating higher than 4?

(Hint: array of objects, .filter, .map)

A

get all moves in 2018, rating > 4, sort in desc order (high rating first)

pick only title property, display on console

152
Q

What is the key difference between function declarations and function expressions?

A

we can call function declaration before it’s defined!

we cannot call a function expression before it’s defined!

Why?

Hosting - moving function declarations automatically to top of file by JavaScript

153
Q

Why can we call a function declaration before it’s declaration?

A

Popular JavaScript interview question!!

Hosting

JavaScript engine automatically moves function declarations to top of file

154
Q

What should we remember about hoisting?

(Hint: scope, declarations, assignments)

A
155
Q

What is unique about a function’s arguments in JavaScript?

(Hint: dynamic)

A

Can pass more arguments or less arguments

156
Q

How can we write code to allow varying numbers of arguments in our JavaScript functions?

(Hint: arguments object)

A

iterate the arguments object

What is the arguments object?

used to work with a function that has a varying number of arguments passed

BUT!

ES6 offers rest operator!

157
Q

What is the rest operator?

(hint: (…args) )

A

ES6 for varying number of args

puts the args in an array

elegant and professional

less code (no looping)

158
Q

What can we not have after the rest parameter?

A

Another parameter!

can have zero or more parameters before rest!

Rest parameter has to be the last parameter!

159
Q

How do we give a function default values?

(Hint: OR operator vs. ES6)

A

parameter with default value must be last

Cannot have a parameter without a default value following

160
Q

How can we write code for getters and setters in JavaScript?

A

only read only!

161
Q

How can we use defensive programming in JavaScript?

(Hint: throw an Error ( ) and catch it)

A
162
Q

What is the scope of ‘const’ variables in JavaScript?

A

Scope of constant is limited to the code block it is defined

cannot access const outside function, for loop, if loop it is defined

163
Q

What is the var keyword?

(Hint: how does it differ from let?)

A

scope of var is not limited to the block defined

var => function scope variable

it’s limited to the function it’s defined!

ES6 (ES2015) introduced - let and const

let, const => block scope variables

164
Q

What is the problem with declaring variables using the “var” keyword in JavaScript?

(Hint: window object)

A

It attaches the variable to the window object (browser object)

if using a 3rd party library with same variable name, can override your variable

165
Q

What does the .this keyword refer to in JavaScript?

(Hint: part of obj or not?)

A
166
Q

How can we write code to flatten an array passed in the spread operator?

(Hint: varying args -> spread operator -> puts all into an array)

A

If passing an array to the spread operator,

will encapsulate into an array

creating a nested array

must flatten, to sum

167
Q

How do we write code to calculate the area of a circle?

(Hint: getter function)

A
168
Q

How can we write code to validate an input and throw an error?

(Hint: throw an error, try/catch block)

A
169
Q

What are the next steps?

(Hint: JavaScript Object Oriented Programming)

A

Why?

A lot of developers write JavaScript applications without properly understanding the inner workings of JavaScript.

They keep “trying” things until it works out.

Don’t be one of these!

Get a solid foundation of the inner workings of JavaScript

It’s an immense help to your career