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
Q

What are the keys for the values inside an array?

A

Name of the Array & Value of the array

26
Q

DOM Manip 1

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

A

if you are planning to use it multiple times

27
Q

DOM Man 2

Why use .textContent?

A

collects and updates JUST the text.

28
Q

Why is it so important to be able to dynamically update text?

A

So the website can be more responsive to the user

29
Q

What datatype are the values you remove from a text input?

A

from a text input, we will always pull out a string.

30
Q

What is the difference between the getElementById() method and the querySelector() method?

A

id = HTML ID

querySelector = class or element

31
Q

Does a callback function require a name?

A

No, they can be anonymous

32
Q

What is the purpose of a loop?

A

Allows you to repeat an action; checking conditionals

33
Q

What is the purpose of a conditional expression as it relates to loops?

A

Gives the ability to start, stop, and implement the while loop

34
Q

How does a for loop differ from a while loop?

A

For: Already know how many times to execute
While: Don’t know how many times they will run

35
Q

Which pieces of information provided in the parentheses for a for loop are mandatory?

A
for (let i = 0; i < 9; i++) {
  codeblock;
}
36
Q

What is a for in loop?When is it good to use?

A

for loop that iterates through an object; object literal

37
Q

How do you target a value of a property in an object?

A

using bracket notation.

38
Q

What is the difference between the parentNode and parentElement properties?

A

parentNode: Finds elements for containing elements in HTML

**parentElement: Returns NULL when HTML doesnt have a parent element node.

39
Q

Why is it important to be able to traverse the DOM?

A

You have the ability to select other elements in regards to the
(parent, sibling, and child)

40
Q

What are two ways to target elements on the DOM?

A
  • querySelector

- getElementbyId

41
Q

What is another way to add a text node to an element other than using .textContent?

A

.createTextNode( )

42
Q

How do you create a HTML element using vanilla Javascript?

A

document.createElement(‘ ‘)

43
Q

Why is using loops and arrays for creating multiple dom elements preferable to creating them one at a time?

A

Faster and more efficient. It is much more concise with a loop.

44
Q

Why are arrays preferred over objects for the functionality ?

A

Arrays are indexed. You are able to control what you are able to use in terms of DOM Creation

45
Q

Why is it important to be able to retrieve and use data from inputs?

A

Gathering user input in general.

46
Q

Why is it dangerous to assume you have the correct data when creating elements?

A

Your code may not be responsive. It can cause user to make problems into the input

47
Q

JS oop 5

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

A

An empty object is created

48
Q

JS OOP5

Since classes are technically classes. Can you name a difference between classes and functions?

Class*constructor

A

Classes use a ‘new’ keyword.
‘new’ keyword makes an object.

Functions you can call with ( )

49
Q

What is a static method?

A

Methods attached to the creator object.

- use it off of the creator not the object itself

50
Q

Variables defined with the var keyword are function scoped. const and let are _____ scoped.

A

block scoped

51
Q

Name some characteristics of a variable declared using const.

A

cannot be hoisted

52
Q

Name some characteristics of a variable declared using let.

A

cannot be hoisted

53
Q

What does block scoped mean?

A

By the closest { }

54
Q

In the file we can push a new value to an array defined using the const variable. How does that work?

A

you are modifying the reference data type in memory, not the actual variable

55
Q

Name some things that var can do that const and let can’t.

A

var can be hoisted, becomes a property of the window object. Can be redeclared and reassigned.