JS Flashcards

1
Q

What is a variable?

A

JS variables are containers for storing data values.

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

Why are variables useful?

A

Because we can change the value of a variable and can reuse them as well. Also useful for readability!

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

What two special characters can a variable begin with?

A

$ and _

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

How do you declare a variable?

A

You can do: var variable name

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

How do you assign a value to a variable?

A

variable name = value you want to assign

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

Are variables case sensitive?

A

Yes

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

Which words cannot be used as variable names?

A

reserved words (JS keywords)

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

What is a string?

A

A JS String stores a series of characters like “Tia Kim”.

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

What is the string concatenation operator?

A

It produces a new string by appending the second operand onto the end of the first operand.

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

What is the difference when it comes to using single quotes or double quotes ( ‘ ‘ or “ “ )?

A

No difference.

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

How do you escape quotation characters?

A

You can use \ to escape quotation characters.

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

What is type coercion?

A

Type coercion is the process of converting value from one type to another.

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

What is a number in JavaScript?

A

It represents and manipulate numbers.

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

What is an arithmetic operator?

A

It takes numerical values as their operands and return a single numerical value.

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

Name four of the arithmetic operators?

A

+, -, /, *

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

What is the order of execution?

A

Multiplication and division are performed before addition or subtraction.

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

What is a boolean?

A

Boolean is a data type that returns either true or false.

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

What is a comparison operator?

A

A comparison operator compares its operands and returns a Boolean value based on whether the comparison is true.

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

What is the difference between undefined and null?

A

Undefined is a type and null is an object.

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

What advantages do you see with using a grid system?

A

Easier to stay organized with the layout,

mobile responsiveness, consistency, etc.

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

What is a function?

A

A function is a block of code that performs a particular task.

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

Why are functions useful?

A

Because you can use it multiple times with different arguments.

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

How do you call a function?

A

With its name followed by parentheses.

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

What are the parts of a function definition?

A

Function keyword, function name, code block.

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

Parameters vs arguments

A

Parameters are the names listed in the function definition and arguments are the real values that are passed to the function.

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

Why is it important to understand truthy and falsy values?

A

Because it is important when writing conditional statements in code.

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

Why is the typeof null an object?

A

It’s a bug.

28
Q

What is the difference between null and undefined?

A

Undefined is a variable that has been declared but not assigned a value and null is assigned and means empty.

29
Q

Why do you always use === for comparisons?

A

Because it doesn’t do type coercion so it can prevent you from doing unexpected type coercion.

30
Q

What is the primary use case for switches?

A

When you want to compare one value with multiple values, you use switch statement.

31
Q

Does the default case have to be at the bottom of the switch statement?

A

By convention, the default clause is the last clause, but it does not need to be so.

32
Q

What happens if there is no break statement between cases?

A

The program will run statements from the matching case to the end of the line.

33
Q

What is an object in JavaScript?

A

An object groups a set of variables and functions together.

34
Q

What is a property in relation to JavaScript objects?

A

A property of an object is a variable that is attached to the object.

35
Q

When should you use bracket notation over dot notation with objects?

A

When the property’s name is in numbers.

36
Q

When should you use bracket notation over dot notation with objects?

A

When the property’s name is in numbers or includes spaces or if you have a variable that you need to substitute.

37
Q

What is an array in JavaScript?

A

It stores a list of values in a single variable.

38
Q

How do you create an array literal?

A

You can create it with square brackets.

39
Q

What are the keys for the values inside an array?

A

The index.

40
Q

Arrays have a property named length. Because arrays have a properties, what other data structure are they similar to?

A

Object.

41
Q

What is the primary advantage to storing your selected elements in a variable?

A

You can re-reference to the element without having the browser to look through the DOM tree to find the same element again.

42
Q

Why might you need JavaScript to modify the DOM after the page loads?

A

To be interactive with a user. Also we can update the content of the web page in a more efficient way.

43
Q

How can you better prepare when writing HTML for DOM manipulation in your JavaScript code?

A

Create IDs, classes, etc.

44
Q

Why is the Window.event property useful for finding an element which was interacted with?

A

Because it tells you which event is happening - if it’s a mouse event then you can guess that maybe something was clicked

45
Q

Why is the Window.event property to be avoided in new code?

A

?

46
Q

Who passes in the event object into the handleClick callback function?

A

Javascript!

47
Q

What is jQuery?

A

jQuery is a JS library designed to simplify HTML DOM tree traversal and manipulation, as well as event handling, CSS animation, and Ajax.

48
Q

What is the jQuery selector function?

A

It is a function which makes use of expressions to find out matching elements from a DOM based on the given criteria.

49
Q

What does the jQuery selector function return?

A

It returns a collection of matched elements either found in the DOM based on the passed arguments or created by passing an HTML string.

50
Q

What are some downsides from using jQuery over vanilla Javascript?

A

The library is huge to download?

51
Q

Why do we use the tag at the bottom of the body, instead of putting it inside the <head> tag?

A

If we put the script tag at the bottom of your html body, it gives the html time to load before any of the js loads, so it prevents from having errors and speed up website response time.

52
Q

What is event bubbling?

A

Event bubbling is a type of event propagation where the event first triggers on the innermost target element, and then successively triggers on the ancestors of the target element in the same nesting hierarchy till it reaches the outermost DOM element or document object.
(It’s a type of event propagation where the most specific node gets triggered first and then the event flows outwards to the least specific ones)

53
Q

What is the difference between event.target and event.currentTarget.

A

event.currentTarget tells you where the event is attached to and event.target tells you where the user clicked on.

54
Q

What is the first argument the function setTimeout takes?

A

A function that is going to be executed after the timer expires.

55
Q

What does the setInterval function return?

A

It returns an intervalID which is a numeric, non-zero value which identifies the timer created by the call to setInterval().

56
Q

What is a call stack?

A

A call stack is a mechanism for an interpreter to keep track of its place in a script that calls multiple functions.
(It’s where JS keeps track of all the operations in line to be executed)

57
Q

What is the event loop?

A

It’s a programming design patter that waits for and dispatches events or messages in a program.
(It looks at the call stack and the call back queue, and if the call stack is empty it will take the first event from the queue and push it to the call stack)

58
Q

What does the term blocking mean?

A

It’s when something(render queue) blocks events in the queue to be moved over to the stack.

59
Q

What is a method?

A

A method is a function which is a property of an object.

60
Q

What does a method do?

A

Whatever the code inside the block tells you to do

61
Q

What does the new keyword do?

A

The new operator lets developers create an instance of a user-defined object type or one of the built-in object types that has a constructor function.

62
Q

I could’ve added a method to the constructor function by assigning a method to a property on the this object. Why do we have to add it to the prototype property?

A

To save memory space

63
Q

What is the first thing that happens in a class when it is instantiated with the new keyword?

A

It creates a blank, plain JS object -> Links (sets the constructor of) this object to another object -> Passes the newly created object from step 1 as the this context -> Returns this if the function doesn’t return an object

64
Q

Difference between functions vs classes?

A

Function declarations are hoisted and class declarations are NOT.

65
Q

What is a static method?

A

Static methods CANNOT be called through a class instance. They are called without instantiating their class. Often used to create utility functions for an application.

66
Q

What is the benefit of instantiating Classes within other classes?

A

You can inherit their constructor and don’t have to re-write the same code lines. Also when there is a tie between the classes.

67
Q

What is the basic idea of OOP?

A

The idea is to model real world things that we want to represent inside our code.