JS Flashcards

1
Q

What is a variable?

Why are variables useful?

A

container that stores information such as strings, numbers, booleans etc

They are able to be reused and reassigned to a value; concise for readability

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

How do you declare a variable?

How do you assign a value to a variable?

A

var ( keyword ) = name( value )

( = ) assignment operator

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

What is a string?

What is the string concatenation operator?

A

0 or more characters inside quotes.
it is the data type stored in quotes

(+) Adds the first and second string together

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

How do you escape quotation characters?

A

( \ ) As a character to prevent interpreting a quote as the end of a string

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

What is type coercion?

A

Is the process of converting a value from one to another.

ex: number will become a string with concatenation

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

What is a number in JavaScript?

A

A primitive data type by literals

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

What is an arithmetic operator?

Name four of the arithmetic operators?

A

operator and operand; anything that can do math

+,-,*, /

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

What is a boolean?

A

Variable that can only have a value of true or false

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

What is a comparison operator?

A

=== ; same type and same content

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

What is the difference between undefined and null?

A

undefined: variable declared. but no value, it is default.
null: object, is an assignment value of nothing, needs to be set to Null. (assigned on purpose)

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

What is a function and why are they useful?

A

A function is a set of statements that perform a task. Functions are useful because they are expressions that can have a return value

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

How do you call a function?

What are the parts of a function definition?

A
function name(parameter ) {
}
function keyword , function name , (parameters) {
code block
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between a parameter and an argument?

A

Parameter: Space prepared for data; variable in method definition

Argument: Value that goes into the variable. Data that is passed through parameters.

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

Why is it important to understand truthy and falsy values?

A

allow use the ability to use conditionals.

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

Falsy Values

A
if (false)
if (null)
if (undefined)
if (0)
if (-0)
if (0n)
if (NaN)
if ("")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Truthy Values

A
if (true)
if ({})
if ([])
if (42)
if ("0")
if ("false")
if (new Date())
if (-42)
if (12n)
if (3.14)
if (-3.14)
if (Infinity)
if (-Infinity)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Logical Operators:
and
or
not

A

&&
||
!

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

What happens if there is no break statement between cases?

A

It will fall through. it’ll run cases that fall below.

instead of switch statements, a conditional can be written.

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

What is an object in JavaScript?

A

data type that stores data

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

How do you create an object literal?

A

var keyword = { }

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

What is a property in relation to JavaScript objects?

A

it is a key-value pair

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

Dot notation?

A

object.property = value;

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

Bracket Notation?

A

object[‘property’] = ‘value’;

24
Q

What is an array in JavaScript?

How do you create an array literal?

A

variable that stores a list of values

var arr = [ ‘one’, ‘two’, ‘three’]

25
What are the keys for the values inside an array?
Name of the Array & Value of the array
26
DOM Manip 1 | What is the primary advantage to storing your selected elements in a variable?
if you are planning to use it multiple times
27
DOM Man 2 | Why use .textContent?
collects and updates JUST the text.
28
Why is it so important to be able to dynamically update text?
So the website can be more responsive to the user
29
What datatype are the values you remove from a text input?
from a text input, we will always pull out a string.
30
What is the difference between the getElementById() method and the querySelector() method?
id = HTML ID querySelector = class or element
31
Does a callback function require a name?
No, they can be anonymous
32
What is the purpose of a loop?
Allows you to repeat an action; checking conditionals
33
What is the purpose of a conditional expression as it relates to loops?
Gives the ability to start, stop, and implement the while loop
34
How does a for loop differ from a while loop?
For: Already know how many times to execute While: Don't know how many times they will run
35
Which pieces of information provided in the parentheses for a for loop are mandatory?
``` for (let i = 0; i < 9; i++) { codeblock; } ```
36
What is a for in loop?When is it good to use?
for loop that iterates through an object; object literal
37
How do you target a value of a property in an object?
using bracket notation.
38
What is the difference between the parentNode and parentElement properties?
parentNode: Finds elements for containing elements in HTML **parentElement: Returns NULL when HTML doesnt have a parent element node.
39
Why is it important to be able to traverse the DOM?
You have the ability to select other elements in regards to the (parent, sibling, and child)
40
What are two ways to target elements on the DOM?
- querySelector | - getElementbyId
41
What is another way to add a text node to an element other than using .textContent?
.createTextNode( )
42
How do you create a HTML element using vanilla Javascript?
document.createElement(' ')
43
Why is using loops and arrays for creating multiple dom elements preferable to creating them one at a time?
Faster and more efficient. It is much more concise with a loop.
44
Why are arrays preferred over objects for the functionality ?
Arrays are indexed. You are able to control what you are able to use in terms of DOM Creation
45
Why is it important to be able to retrieve and use data from inputs?
Gathering user input in general.
46
Why is it dangerous to assume you have the correct data when creating elements?
Your code may not be responsive. It can cause user to make problems into the input
47
JS oop 5 What is the first thing that happens in a class when it is instantiated with the 'new' keyword
An empty object is created
48
JS OOP5 Since classes are technically classes. Can you name a difference between classes and functions? Class*constructor
Classes use a 'new' keyword. 'new' keyword makes an object. Functions you can call with ( )
49
What is a static method?
Methods attached to the creator object. | - use it off of the creator not the object itself
50
Variables defined with the var keyword are function scoped. const and let are _____ scoped.
block scoped
51
Name some characteristics of a variable declared using const.
cannot be hoisted
52
Name some characteristics of a variable declared using let.
cannot be hoisted
53
What does block scoped mean?
By the closest { }
54
In the file we can push a new value to an array defined using the const variable. How does that work?
you are modifying the reference data type in memory, not the actual variable
55
Name some things that var can do that const and let can't.
var can be hoisted, becomes a property of the window object. Can be redeclared and reassigned.