JavaScript Flashcards

1
Q

what is the purpose of variables

A

Variables are containers for storing data

Variables store data values

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

How do you declare a varaible?

A

Ways to Declare a JavaScript Variable:

Using var
Using let
Using const

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

How do you initialize (assign a value to) a variable?

A

To initialize (assign a value to) a variable, you use the equal sign =

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

what characters are allowed in variable names?

A

variable names can’t contain spaces

variable names must begin with a letter, an underscore, or a dollar sign

variable names can contain letters, underscores, numbers, or dollar signs

variables are case sensitive

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

What does it mean to say that variable names are case sensitive?

A

It means that the case matters

cat =/= Cat

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

What is the purpose of a string?

A

JavaScript strings are for storing and manipulating text

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

what is the purpose of a number?

A

The purpose of numbers is to represent and manipulate numbers

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

what is the purpose of boolean?

A

A JavaScript Boolean represents one of two values: true or false.

Very often, in programming, you will need a data type that can only have one of two values, like

YES / NO
ON / OFF
TRUE / FALSE
For this, JavaScript has a Boolean data type. It can only take the values true or false.

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

what does the = operator mean in JavaScript?

A

the = operator is an assignment operator.

it assigns value to JavaScript variables

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

how do you update the value of a variable?

A

You update the value of a variable by reassigning it using the assignment operator =

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

what is the difference between null and undefined

A

The undefined property indicates that a variable has not been assigned a value, or not declared at all.

null is a special value that represents an empty or unknown value.

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

why is it a good idea to include labels when you log values to the browser console?

A

so you know when shit dont work

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

give five examples of JavaScript primitives

A

string, number, boolean, null, undefined

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

what data type is returned by an arithmetic operation

A

number data type is returned by arithmetic operation

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

what is string concatenation?

A

string concatenation is the combining of strings

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

what purpose does the addition (+) operator serve in JavaScript

A

the addition (+) can be used for arithmetic or concatenating strings

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

what data type is returned by comparing two values with logical operators?

A

boolean data type is returned when comparing two operands with logical operators

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

what does the addition assignment (+=) operator do?

A

the addition assignment (+=) operator assigns the result of the expression back to the first value

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

what are objects used for

A

An object is a collection of related data and/or functionality.

These usually consist of variables and functions
(which are called properties and methods when they are inside objects).

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

what are object properties?

A

An object is a collection of related data and/or functionality. These usually consist of several variables and functions (which are called properties and methods when they are inside objects).

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

describe object literal notation

A

{
key: value
}

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

How do you remove a property from an object?

A
To delete a property from an object, you can use the delete operator
Delete Object.Property
Delete person(object).name(property)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What are two ways to get or update the value of a property?

A

The two ways to get or update the value of a property are dot and bracket notation

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

What are arrays used for?

A

An array is a special variable, which can hold more than one value
Arrays are used to store data
Think of arrays as lists

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation
``` Array literal notation looks like the following: var newArr = [] ```
26
How are arrays different from plain objects?
Objects represent things with properties and methods | Array create and store lists of data in a single variable
27
What number represents the first index of an array?
Zero is the number which represents the first index of an array Arrays are based on zero index, meaning arrays start a 0 instead of 1
28
What is the length property of an array?
he length property of an array returns the length of an array The length is 1 indexed, meaning the count starts at 1 The length is not 0 indexed
29
How do you calculate he last index of an array?
To calculate the last index of an array, you would use the .length property and subtract 1 You subtract 1 because .length property is 1 indexed, and arrays are 0 indexed
30
What is a function in JavaScript?
A JavaScript function is a block of code designed to perform a particular task A JavaScript function is executed when something invokes/calls it
31
Describe the parts of a function definition (when a function is being created)
A JavaScript function is defined with the function keyword, followed by a name followed by parentheses
32
What characters are allowed for function names?
Function names can contain letters, digits, underscores, and dollar signs (same rule as variables)
33
What can be included within the parentheses of a function definition?
a function definition's parentheses can contain parameters separated by commas
34
Describe the parts of a function call
The parts of a function call include the name of the function along with any arguments that may or may not be passed
35
When comparing them side-by-side, what are the differences between a function call and a function definition?
a function definition has the function keyword preceding (coming before) the name Function definition: function sampleFunction() Function call: sampleFunction()
36
Why are function parameters useful?
Function parameters are useful because they hint at what values should be passed in as arguments for the function
37
What two effects does a return statement have on he behavior of a function
When JavaScript reaches a return statement, the function will stop executing. Functions often compute a return value. The return value is returned back to the caller
38
What is a method?
JavaScript methods are actions that can be performed on objects A JavaScript method is a property containing a function definition Methods are functions stored as object properties You access an object method with the following syntax: objectName.methodName()
39
How is a method different from any other function?
A function can be called without an object A method is a function that is associated with a particular object
40
How do you remove the las element from an array?
You can use he array.pop() method to remove elements from the end of an array
41
How do you round a number down to the nearest integer?
You can round down to he nearest integer with the Math.floor() method Example: Math.floor(1.6) returns 1
42
How do you generate a random number?
You can generate a random number with the Math.random() function Example: Math..Random(100) returns a number from 1 - 100
43
How do you delete an element from an array?
You can use the array.splice() method to remove elements from an array You can use the array..pop() method to remove elements from the end of an array You can use the array.shift() method to remove elements from the front of an array
44
How do you append an element to an array?
You can use the array.push() method to append an element to an array You can also use array[array.length] = value
45
How do you break a string up into an array?
You can use the string.split() method to break a string into an array
46
Do string methods change the original string? How would you check if you weren't sure?
No, string methods do not change the original string Strings are immutable You could check by console.log('string')
47
Is the return value of a function or method useful in every situation?
No, the return value of a function or a method is not useful in every situation, it can be excluded
48
What are comparison operators?
Comparison operators are used in logical statements to determine equality or difference between variables or values
49
Give 6 examples of comparison operators
``` === !== >< >= <= ```
50
What data type do comparison expressions evaluate to?
Comparison expressions evaluate to boolean values (true or false)
51
What is the purpose of an if statement?
If statements are used to execute specific JavaScript code blocks if a condition is true
52
Is else required in order to use an if statement?
No
53
Describe the syntax of an if statement
if (condition) { code to be executed if condition is true }
54
What are the three logical operators?
&& (and) || (or) ! (not)
55
How do you compare two different expressions in the same condition?
You can compare two different expressions in the same condition by wrapping the expression in parenthesis
56
What is the purpose of a loop?
To repeat an action
57
What is the purpose of a condition expression in a loop?
the condition expression of a loop = the brakes for the loop the purpose of the condition expression in a loop is to tell the loop when to stop (the brakes) condition - a boolean expression to be evaluated before each loop iteration. If this expression evaluates to true, the inner commands will be executed
58
What does iteration mean in the context of loops?
Every time the loop runs through the code block
59
What is a condition within the context of a for loop?
A condition is an expression to be evaluated before each loop iteration If this expression evaluates to true, statement is executed
60
What is a statement within the context of a for loop?
A statement is what's contained within the opening curly brackets for the for loops' code block A statement ( code within the code block ) that is executed as long as the condition evaluates to true
61
When does the condition expression of a while loop get evaluated?
before each loop iteration
62
When does the initialization expression of a for loop get evaluaed?
The initialization expression of a for loop gets evaluated at the beginning ( initialization )
63
When does the condition expression of a for loop get evaluated?
before each loop iteration
64
When does the final expression of a for loop get evaluated?
The final expression of a for loop gets evaluated after the code block / at the end
65
Besides a return statement ( which exits its entire function block ) which keyword exits a loop before its condition expression evaluates to false?
The break statement keyword exits a loop before its condition expression evaluates to false
66
what does the ++ increment operator do?
The increment operator ( ++ ) increments ( adds one to ) its operand ( data value ) and returns a value
67
What is an operand?
an operand is a data value
68
how do you iterate through the keys of an object?
you iterate through the keys of an object with a for in loop the for in loop iterates ( loops ) over the properties ( keys ) of an object The code block inside the loop is executed once for each property The properties ( keys ) are the condition. The code runs for however many keys there are
69
Which document is being referred to in the phrase Document Object Model ( DOM )
The document object the html document
70
What is a DOM tree?
The HTML DOM model constructed as a tree of objects ( HTML elements represented as DOM elements )
71
Give two examples of document methods that retrieve a single element from the DOM
document.querySelector() getElementByID()
72
Give one example of a document method that retrieves multiple elements from the DOM at once
document.querySelectorAll()
73
Why might you want to assign he return value of a DOM query to a variable Why would you do this: var pElement = document.querySelector('p')
You might want to add/change/remove the element You might want to add/change/remove the element's attributes You might want to add/change/remove the events associated with the element or element's parent/descendants
74
what console method allows you to inspect the properties of a DOM element object?
console.dir()
75
why would a tag need to be placed at the bottom of the HTML content instead of at the top?
because when the browser loads the page, it must complete loading relevant JS scripts/files before loading the rest of the page. this causes a slow page load / bad UX
76
what does document.querySelector() take as its argument and what does it return?
document.querySelector() takes CSS selectors as its argument
77
What is the purpose of events and event handling?
to execute code when an event occurs
78
what is a callback function?
a callback function is a function passed into another function as an argument
79
what is the event.target?
the event.target is the location of the event trigger .target is a property of the event object
80
what is the className proeprty of element objecs?
the className property sets or returns an element's class attribute