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
Q

Describe array literal notation

A
Array literal notation looks like the following:
var newArr = []
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

How are arrays different from plain objects?

A

Objects represent things with properties and methods

Array create and store lists of data in a single variable

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

What number represents the first index of an array?

A

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

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

What is the length property of an array?

A

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

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

How do you calculate he last index of an array?

A

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

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

What is a function in JavaScript?

A

A JavaScript function is a block of code designed to perform a particular task
A JavaScript function is executed when something invokes/calls it

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

Describe the parts of a function definition (when a function is being created)

A

A JavaScript function is defined with the function keyword, followed by a name followed by parentheses

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

What characters are allowed for function names?

A

Function names can contain letters, digits, underscores, and dollar signs (same rule as variables)

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

What can be included within the parentheses of a function definition?

A

a function definition’s parentheses can contain parameters separated by commas

34
Q

Describe the parts of a function call

A

The parts of a function call include the name of the function along with any arguments that may or may not be passed

35
Q

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

a function definition has the function keyword preceding (coming before) the name

Function definition: function sampleFunction()

Function call: sampleFunction()

36
Q

Why are function parameters useful?

A

Function parameters are useful because they hint at what values should be passed in as arguments for the function

37
Q

What two effects does a return statement have on he behavior of a function

A

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
Q

What is a method?

A

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
Q

How is a method different from any other function?

A

A function can be called without an object

A method is a function that is associated with a particular object

40
Q

How do you remove the las element from an array?

A

You can use he array.pop() method to remove elements from the end of an array

41
Q

How do you round a number down to the nearest integer?

A

You can round down to he nearest integer with the Math.floor() method

Example: Math.floor(1.6) returns 1

42
Q

How do you generate a random number?

A

You can generate a random number with the Math.random() function

Example: Math..Random(100) returns a number from 1 - 100

43
Q

How do you delete an element from an array?

A

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
Q

How do you append an element to an array?

A

You can use the array.push() method to append an element to an array

You can also use array[array.length] = value

45
Q

How do you break a string up into an array?

A

You can use the string.split() method to break a string into an array

46
Q

Do string methods change the original string? How would you check if you weren’t sure?

A

No, string methods do not change the original string

Strings are immutable

You could check by console.log(‘string’)

47
Q

Is the return value of a function or method useful in every situation?

A

No, the return value of a function or a method is not useful in every situation, it can be excluded

48
Q

What are comparison operators?

A

Comparison operators are used in logical statements to determine equality or difference between variables or values

49
Q

Give 6 examples of comparison operators

A
===
!==
><
>=
<=
50
Q

What data type do comparison expressions evaluate to?

A

Comparison expressions evaluate to boolean values (true or false)

51
Q

What is the purpose of an if statement?

A

If statements are used to execute specific JavaScript code blocks if a condition is true

52
Q

Is else required in order to use an if statement?

A

No

53
Q

Describe the syntax of an if statement

A

if (condition) {

code to be executed if condition is true

}

54
Q

What are the three logical operators?

A

&& (and)
|| (or)
! (not)

55
Q

How do you compare two different expressions in the same condition?

A

You can compare two different expressions in the same condition by wrapping the expression in parenthesis

56
Q

What is the purpose of a loop?

A

To repeat an action

57
Q

What is the purpose of a condition expression in a loop?

A

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
Q

What does iteration mean in the context of loops?

A

Every time the loop runs through the code block

59
Q

What is a condition within the context of a for loop?

A

A condition is an expression to be evaluated before each loop iteration

If this expression evaluates to true, statement is executed

60
Q

What is a statement within the context of a for loop?

A

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
Q

When does the condition expression of a while loop get evaluated?

A

before each loop iteration

62
Q

When does the initialization expression of a for loop get evaluaed?

A

The initialization expression of a for loop gets evaluated at the beginning ( initialization )

63
Q

When does the condition expression of a for loop get evaluated?

A

before each loop iteration

64
Q

When does the final expression of a for loop get evaluated?

A

The final expression of a for loop gets evaluated after the code block / at the end

65
Q

Besides a return statement ( which exits its entire function block ) which keyword exits a loop before its condition expression evaluates to false?

A

The break statement keyword exits a loop before its condition expression evaluates to false

66
Q

what does the ++ increment operator do?

A

The increment operator ( ++ ) increments ( adds one to ) its operand ( data value ) and returns a value

67
Q

What is an operand?

A

an operand is a data value

68
Q

how do you iterate through the keys of an object?

A

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
Q

Which document is being referred to in the phrase Document Object Model ( DOM )

A

The document object

the html document

70
Q

What is a DOM tree?

A

The HTML DOM model constructed as a tree of objects ( HTML elements represented as DOM elements )

71
Q

Give two examples of document methods that retrieve a single element from the DOM

A

document.querySelector()

getElementByID()

72
Q

Give one example of a document method that retrieves multiple elements from the DOM at once

A

document.querySelectorAll()

73
Q

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’)

A

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
Q

what console method allows you to inspect the properties of a DOM element object?

A

console.dir()

75
Q

why would a tag need to be placed at the bottom of the HTML content instead of at the top?

A

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
Q

what does document.querySelector() take as its argument and what does it return?

A

document.querySelector() takes CSS selectors as its argument

77
Q

What is the purpose of events and event handling?

A

to execute code when an event occurs

78
Q

what is a callback function?

A

a callback function is a function passed into another function as an argument

79
Q

what is the event.target?

A

the event.target is the location of the event trigger

.target is a property of the event object

80
Q

what is the className proeprty of element objecs?

A

the className property sets or returns an element’s class attribute