Ultimate JavaScript Mastery - Part 1 Flashcards

1
Q

What is JavaScript?

A

A programming language written to be executed within the browser

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

What can you do with JavaScript?

A

Modern JavaScript can also be used as a server side language as well as front end

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

Where does JavaScript code run?

A

Originally meant to run only in the browser, but can now be run outside the browser using node

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

Describe the difference between JavaScript and ECMAScript

A

ECMAScript is simply the standard for which JavaScript, a programming language, is written

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

Where should you place your tag within the browser?

A

The tag should be written at the end of the body section.

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

What is a statement?

A

A piece of code that expresses actions to be carried out.

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

Write a script tag

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

What are the data types in JavaScript?

A

Primitive (Value) Types and Data Types

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

Name the Primitive (Value) Types

A
String
Number
Boolean
undefined
null
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe Dynamic Typing

A

JavaScript is a Dynamic Programmming language because variable types can be changed

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

Name the Reference Types

A

Object
Array
Function

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

What is an object?

A

A piece of code that stores data via key/value pairs. The keys are known as the properties of the object.

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

A key in an object is also known as what?

A

Property

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

What are the two ways to access properties within an object?

A

Dot Notation
ex. person.name = “Kevin”

Bracket Notation
ex. person[‘name] = “Kevin”

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

What are the names of the JavaScript operators?

A

Arithmetic - takes two operands and produces a new value (+, -, *, /, %, ++, –)

Assignment - assigns a value to a variable (=, +=)

Comparison - A comparison between to expressons that returns a boolean value such as ‘true’ or ‘false’ (>, >=,

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

Give an example of a ternary (conditional) operator

A
A ternary operator can evaluate an expression and provide two an option if it is true, and an option if false
ex if(age >=21 ? "Old Enough" : "Too Young")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are “falsy” values?

A

Any expression that evaluates to any of the following will return false.

undefined
null
0
false
""
NaN
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is an advantage of using non the logical “or” ( || ) operator with non boolean values?

A

Using the logical “or” ( || ) with non boolean values will allow you to set default values. For example, if something doesn’t exist, you can have a default value set. For example, If a user hasn’t signed in, you can set mount a default component such as the login

19
Q

What are the 2 conditional statements?

A
If...else
if(condition) {
  statement
} else if {
  statement
} else {
  statement
}
switch..case
let name = "Kevin"
switch (name) {
  case "Kevin" : console.log("Hello, Kevin");
  break;

case “Preye” : console.log(“Hello, Preye”);
break;

default: console.log(“Hello, guest”)
}

20
Q

Describe the difference between “==” and “===” operators

A

The “===” operators evalueates both value and type, whereas “==” evaluates just value.

21
Q

What are the 5 kinds of Loops?

A

For
While
Do…While
For…of

22
Q

What is the anatomy of a for loop?

A

The for loop requires 3 statements within the parenthesis

for (let i = 0; i <= arr.length; i++) {
  console.log("Hello World")
}
for (initalExpression; condition; incrementExpression) {
  statement
}
23
Q

How is a while loop different from the for loop?

A

Within a for loop, the loop variable (i) is apart of the loop itself. The while loop, however, has to be declared outside of the loop.

let i = 0;
while(i<=arr.length) {
 console.log(i);
 i++
}
24
Q

Construct a “do…while” loop

A
let i = 0
do {
  if (i % 2 !== 0) console.log(i);
  i++;
} while (i < = 5);
25
Q

Describe a for…in loop.

A

A for…in loop is meant to iterate through an object using the syntax
for(let key in fruit )
Fruit is the object being iterated through and key is the current key iteration
Fruit accesses the key and fruit[key] accesses the value

26
Q

Describe a for…of loop

A

A for…of loop is meant to iterate through an array using the syntax
for(let el in array )

27
Q

Describe OOP

A

Object-Oriented Programming

Where a program is a collection of objects that talk to each other to perform so sort of functionality

28
Q

What is a javaScript method?

A

A function within an object

29
Q

Give an example of a factory function.

A
Factory functions are functions that allow parameters with the purpose of creating objects. 
function foo(firstName, lastName) {
  return {
     firstName,
     lastName,
     fullName() {
       console.log(`${firstName} + ${lastName}`)
     }
   }
}
30
Q

Describe a Constructor function

A

A contructor function is a function that creates an object. The properties and methods within the object use the “this” keyword.

When creating an object, you should use the “new” keyword. For example.

const Kevin = new Person(param, param2)

31
Q

Describe Value vs. Reference Types

A

Value types are copied and have no connection to the origin of the value, so if the original variable is changed, the copy isn’t effected. I call them “Simple Values”
(Number, strings, Booleans, Symbols, undefined, null)

Reference values are not copied, they are referenced somewhere in memory, so if the value of the initial variable is changed, it is also changed in any variable referencing the original variable.
Complex values.
(Objects, functions, arrays)

32
Q

What is the shorthand for enumerating through arrays/objects?

A

Arrays
for (let el of arr)

Objects
for (let key of obj)

33
Q

Describe the two modern way to clone an object.

A
const newObj = Object.assign({}, circle)
The first parameter passed in is the new object. The 2nd parameter, circle is the object that is to be cloned. Additional properties can also be assigned
We can also use the spread operator
const newObj = {...circle}
34
Q

Name 5 wasy to create a date object

A
let today = new Date()
let birthday = new Date('November 17, 1984 03:24:00')
let birthday = new Date(1984, 10, 17, 3, 24, 0)
35
Q

Name 7 common Math Methods

A

Math.PI
Ratio of the a circle’s circumference to its diameter; approximately 3.14159.

Math.abs(x)
Returns the absolute value of x.

Math.ceil(x)
Returns the smallest integer greater than or equal to x.

Math.floor(x)
Returns the largest integer less than or equal to x.

Math.max([x[, y[, …]]])
Returns the largest of zero or more numbers.

Math.min([x[, y[, …]]])
Returns the smallest of zero or more numbers.

Math.random()
Returns a pseudo-random number between 0 and 1.

Math.round(x)
Returns the value of the number x rounded to the nearest integer.

Math.sign(x)
Returns the sign of the x, indicating whether x is positive, negative, or zero.

36
Q

Array methods to master

A
.fill
.find
.filter
.map
.includes
.reduce
.sort
.every
37
Q

What is the difference between a function declaration and a function expression

A

A functions declaration is written explicitly as a function whereas a function expression is a function stored within a variable.

38
Q

Describe Hoisting

A

JacaSCript moves all function declarations (functions not save in a variable) to the top of the file.

39
Q

Describe Getters

A

Where a method is used within an object, we can’t access the returned value of the method by using obj.key. In order to do this, we need to write the keyword get before the function. This allows you to access the value with dot notation.

40
Q

Describe Setters

A

Setters allows you to change and save the values of of a method by using set before calling the function

41
Q

What is ‘defensive programming’?

A

Adding error handling at the beginning of a function to make certain that the logic can be performed. This can mean making sure the the input is the correct type, length, etc and returning a ‘throw new Error(‘Value is incorrect’)’. Try and catch blocks

42
Q

What is the difference between let and var?

A

Var is function scoped and let is block scoped. Var is accesible outside of a block which causes bugs as it can be altered.

43
Q

Explain the “this” keyword

A

This refers to the object that is executing the current function. For example, if the function is part of an object (method), then ‘this’ refers to the object. If the function is. a standalone, then this refers to the global object.

When using the constructor function and the operator new, a new empty object is referenced.

Arrow functions allow you to reference the object direcctly without using “.bind( )”

44
Q

Describe the rest operatorand its use.

A

The rest operator is used when multiple parameters are passed into a function
ex. function sum(…numbers) {

}

The rest operator converts the param into an array, which means, if an array is passed into the function, it will result in an array of arrays