JavaScript Flashcards

(213 cards)

1
Q

what does the console keyword refer to?

A

an object, collection of data and actions that can be used in our code

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

how do you print in javascript?

A

console.log( ) ;

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

how do you write a single line comment in JavaScript?

A

with two forward dashes //

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

How do you write a multi-line comment in JavaScript?

A

/ *

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

What are data types?

A

classifications given to different kinds of data used in programming

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

What are the 8 fundamental data types in JavaScript?

A

number (any number, including decimals)

string (any grouping of characters surrounded by single quotes) (string can be thought of as a fancy word for text)

boolean: data type with only two values - true or false
null: intentional absence of a value
undefined: also represents absence of a value, with different uses to null
symbol: unique identifiers
object: collections of related data

BigInt: represents integers of arbitrary length

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

What are the data types number, string, boolean, null, undefined, and symbol referred to as?

A

primitive data types - the most basic data types in the JavaScript language

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

What is the difference between using console.log() to print numbers and text

A

text needs quotation marks around it within the brackets of console.log() whereas numbers do not

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

What is an operator in JavaScript?

A

a character that performs a task in the code

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

Give some arithmetic operators

A
\+ add
- subtract
* multiply
/ divide 
% remainder
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the remainder operator sometimes called?

A

modulo (although it’s not quite a modulo)

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

What does the remainder operator do?

A

prints the remainder (returns the number that remains after the right hand number divides into the left hand number

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

What is the process of appending one string to another called?

A

concatenation

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

What property stores the number of characters in a string?

A

length

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

What are methods?

A

actions we can perform

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

What does math.floor() do?

A

takes a decimal and rounds it to the nearest whole number

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

what does math.random() do?

A

generates a random number between 0 to 1

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

What is a variable?

A

a container for a value that is stored in the computer’s memory
named storage for data

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

What can you do with variables?

A

create a variable with a descriptive name
store or update information stored in a variable
reference or ‘get’ information stored in a variable

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

what keywords can you use to declare variables?

A

let and const

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

What is the conventional way of capitalising in JavaScript called?

A

Camel Casing

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

How does camel casing work?

A

all words are grouped into one long word, the first word is not capitalised, then every word that follows is capitalised

myName
camelCaseEverything

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

what is the operator ‘ = ‘ called?

A

the assignment operator

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

what does the assignment operator do?

A

it assigns a value to a variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Can variable names start with numbers?
no
26
are variable names case sensitive?
yes
27
can variable names be the same as keywords?
no
28
what does the let keyword signal?
that a variable can be reassigned a different value
29
what happens if you don't give a variable a value?
it automatically has a value of undefined
30
what is different about the variable const compared to let
a const variable (short for constant) cannot be reassigned another value, and must be assigned a value when declared
31
What is the increment operator and what does it do?
the increment operator is ++ and it increases the value of the variable by 1
32
What is the decrement operator and what does it do?
the decrement operator is -- and it decreases the value of a variable by 1
33
what does interpolate mean?
insert
34
What can you use the typeof operator for?
to check the data type of a variable
35
What is a code block / block statement indicated by in JavaScript?
curly brackets { }
36
What is this comparison operator? ' === '
the identity operator
37
What do all comparison statements evaluate to?
true or false
38
What are all comparison operators made up of?
two values that will be compared | an operator that separates and compares the values
39
What are the operators that work with booleans called?
logical operators
40
What are the 3 logical operators?
&& - the and operators || - the or operator, also called the pipe operator ! - the not operator, also known the bang operator
41
When would you use the && (the and) operator?
to check if two things are true
42
What can you do if only one condition needs to be true?
the || (pipe / or operator)
43
What does the ! (bang, not) operator do?
reverses/negates the value of a boolean | take a true or false value and return the opposite
44
What values are falsy?
0, empty strings, null, undefined, NaN (not a number)
45
When does JavaScript assign a truthy value in a boolean condition?
when you use the || pipe operator
46
What is short-circuit evaluation?
the semantics of boolean operators in which the second argument is executed or evaluated only if the first argument does not suffice
47
What is a (conditional) ternary operator?
operator that takes 3 operands: a condition, followed by a question mark ?, then an expression to execute if the condition is truthy followed by a colon, followed by an expression to excute if the condition is falsy isNightTime ? console.log('turn on the lights') : console.log('turn off the lights');
48
Where does the 'else if' statement go?
After the if statement and before the else statement(s)
49
What can you use instead of a long list of 'else if' statements
switch
50
What should finish a case clause within switch?
break;
51
What is the syntax for switch?
``` switch (__) { case '___': console.log('____'); break; //as many cases as need default: console.log('___'); break; ```
52
what is a function?
a reusable block of code that groups together a sequence of statements to perform a specific task
53
give a way to create a function
with a function declaration
54
what does a function consist of?
the function keyword, the name of the function / its identifier followed by parentheses, a function body - the block of statements required to perform a task and enclosed in curly brackets ``` keyword identifier ( ) { } ```
55
what is the hoisting?
it allows access to declarations before they're defined
56
is hoisting good practice?
no
57
when is the code inside a function executed
when it is called
58
How do you call a function?
type the function name followed by parentheses functionName ()
59
what do the parameters of a function do?
allow functions to accept input(s) and perform a task using those inputs they are treated like variables within a function
60
parameters act as ___ for values inside a function
placeholders
61
when calling a function with parameters, we ___ the values in the parameters
specify
62
values that are passed to the function when it is called are called ___
arguments
63
how can arguments be passed to a function
as values (eg numbers) or as variables (eg recWidth, recHeight)
64
what do default parameters do?
allow parameters to have a predetermined value in case there is no argument passed into the function / or if the argument is undefined when called
65
how do you pass back information from a function call?
with return, followed by the value you want to return
66
what happens if the value is omitted from return?
undefined is returned instead of the value wanted
67
what do you call functions being called within another function?
helper functions
68
what is usually omitted in a function expression?
function name
69
what is a function with no name called?
an anonymous function
70
how do you define a function inside an expression?
with the function keyword
71
what is the fat arrow notation?
=>
72
what do arrow functions do?
remove the need to type out the keyword function every time you need to create a function
73
how do you use and write functions with the arrow function?
include your function parameters inside brackets ( ) and then add a fat arrow => that points to the function body { }
74
when are parentheses required with function parameters?
when the function has more than one parameter
75
does a one line function need curly braces?
no
76
what is an implicit return?
when a single line function follow the fat arrow notation, removing the need for the return keyword
77
What is initialization?
assigning an initial value to a variable
78
What is common practice when assigning constant variables?
naming the variable in all uppercase, with an underscore between words const FAV_PET =
79
what are the limits on variable naming?
a variable name cannot start with a digit, and must be named with letters, digits, or the symbols $ or _
80
how are arrays written?
inside square brackets [ ]
81
array indexes are __ based?
zero based, meaning that the first item is 0, second is 1, and so on
82
how are JS objects written?
with curly brackets { | }
83
what are function arguments?
values received by the function when it is invoked / called
84
what happens to a function when JS reaches a return statement?
the function stops executing
85
what operator invokes/calls a function?
the parentheses operator ( )
86
what are local variables?
variables declared within a function
87
what does it mean that JavaScript is dynamically types?
that there are different types of data within the .js language, but that variables are not bound to any specific type of data
88
double and single quotes are ___ quotes
simple quotes
89
backtick quotes are ___ quote
extended functionality quotes
90
what is a JS expression?
a snippet of code that evaluates to a value
91
what is a JS expression?
a snippet of code that performs an action
92
when you write a JS function, all the arguments must be ___, not ___
all arguments must be expressions, not statements
93
what shows a template literal in JS?
backticks
94
what are the three methods for extracting part of a string?
slice (start, end) substring (start, end) substr (start, end)
95
what does slice ( ) do?
extracts part of a string and returns the expected part in a new string
96
what parameters does slice ( ) take?
start position and end position
97
what is the difference between slice( ) and substring( )
slice can take negative numbers as parameters, whereas substring cannot
98
what happens if you miss out the second parameter of substring( )
it will cut out the rest of the string from the position of the first parameter
99
what does trim( ) do?
removes whitespace from either side within a string
100
all comparison operators return a ___ value
boolean
101
for boolean values, true becomes ___
1
102
for boolean values, false becomes ___
0
103
=== is a ___ equality operator
=== is a strict equality operator
104
== is an ___ operator
== is an equality operator
105
when converted to a number, null becomes ___
null becomes 0 when converted to a number
106
when converted to a number, undefined becomes ___
undefined becomes NaN (not a number) when converted to a number
107
comparisons convert null to a __
comparisons convert null to a number (0)
108
what does an if statement need after it
``` brackets if ( ) { } ```
109
what are the four logical operators
|| or && and ! not ?? nullish coalescing
110
&& (AND) returns the first __ value, and || (OR) returns the first ___ value
&& (AND) returns the first falsy value, and || (OR) returns the first truthy value
111
the precedence of AND && operator is __ than OR ||
the precedence of AND && operator is higher than OR ||
112
the precedence of ! NOT is the ___ of all logical operators
the precedence of ! NOT is the highest of all logical operators
113
any value that is not false, undefined, null, 0, NaN, or an empty string '' returns ___ when tested as a conditional statement
returns true
114
what is another word for function parameters?
argument (also properties and attributes)
115
how do you specify multiple arguments / parameters within a function
separate them with comments
116
how do you give a default parameter / argument to a function
by adding = after the name of the function function hello ( name = 'Chris')
117
when do you often see anonymous functions?
when the (anonymous) function expects to receive another function as a parameter
118
what is scope?
scope defines where variables can be accessed or referenced
119
what is a block?
the code inside a set of curly braces { }
120
when you declare global variables, they go to the ___ ____
global namespace
121
what is scope pollution?
when too many global variables exist in the global namespace, or when variables are reused across different scopes
122
it’s best practice to define variables in the global scope, true or false?
false | it’s best practice to NOT define variables in the global scope.
123
why should you tightly scope your code?
* makes code more legible * makes code more understandable * makes code easier to maintain * saves memory in code
124
what is an array represented by?
square brackets [ ]
125
what are the contents inside arrays called?
elements
126
what might the .push method also be referred to as?
a destructive array method
127
what is pass by reference?
when you pass an array into a function, if the array is mutated inside the function, that change will be maintained outside the function as well
128
are elements declared within an array with a const variable mutable or constant
the elements within the array assigned to const variable are mutable the elements within the array itself are mutable
129
if an array is passed through a function and mutated, is the mutation maintained outside the function?
yes
130
what is an array stored within another array called?
a nested array
131
how can you iterate a for loop through an array?
use the array's .length property in the loop's condition
132
in loop variable naming convention, what does i stand for
index
133
give a use for nested loops
to compare elements in two arrays
134
how does a nested loop execute?
for each round/iteration of the outer loop, the inner/nested loop will run completely
135
what does a do... while statement do?
executes a task once then keeps doing that task until condition is met
136
how is do... while different to a while loop?
a do while statement will run at least once regardless of whether the condition evaluates to true
137
what is a high-order function?
functions that accept other functions as arguments and/or return functions as output
138
what do arrow functions do?
remove the need to type function every time you create a function
139
in JavaScript, functions are __ class objects
first class objects
140
what does it mean that functions are first class objects?
JS functions can have properties and methods
141
what is a parameter in a function?
a placeholder for the data that gets passed into the function
142
what are functions that get passed into other functions as parameters called?
callback functions
143
what are iteration methods?
built-in JavaScript array methods that help us iterate
144
what are iterators?
methods called on arrays to manipulate elements and return values
145
what notation is used to designate an object literal?
{ } curly brackets
146
how is the data organised in JS objects?
in key-value pairs
147
what is a key in a key value pair?
it's like a variable name that points to a location in memory that holds a value
148
what can a key's value be?
any data type in the languages (including functions or other objects)
149
what is a key's name known as?
its identifier
150
what is returned if you try to access a property that does not exist on an object?
undefined is returned
151
how do you access an object's property?
with dot notation (object.property) or with bracket notation [ ]
152
when must you use bracket notation over dot notation for accessing an object's property?
when accessing keys that have numbers, spaces or special characters
153
are objects mutable or immutable?
mutable
154
when the data stored on an object is a function, that is called a __
method
155
a property is what an object ___ | a method is what an object ___
has | does
156
how are object methods invoked?
by appending the object's name with the dot operator followed by the method name and parentheses key.method( );
157
what does it mean that objects are passed by reference?
when we pass a variable assigned to an object into a function as an argument, the computer interprets the parameter name as pointing to the space in memory holding that object
158
what is the result of objects being passed by reference?
functions which change object properties mutate the object permanently - even if the object is assigned to to a const variable
159
what does the for... in syntax do?
will execute a given block of code for each property in an object
160
are arrays objects?
yes
161
what does the this keyword do?
references the calling object which provides access to the calling object's properties
162
for a method, the calling object is the object the method ___ to
belongs to
163
what happens if you use the this keyword in a method?
the value of this becomes to calling object
164
arrow functions inherently __ an already defined __ value to the function itself that is not the calling object
bind | this
165
should you use arrow functions when using this in a method?
no! avoid!
166
what is privacy in objects?
the idea that only certain object properties should be mutable or able to change in value
167
does JavaScript have built in privacy for objects?
no
168
what is the naming convention for indicating that an object property should not be altered?
placing an underscore at the start of the property name (should prepend the property name) _propertyName
169
what are getters?
getters are methods that get and return the internal properties of an object
170
what do setter methods do?
safely reassign values of existing properties within an object
171
in general, do getters need to be called with parentheses?
no
172
what is a factory function?
a function that returns an object and can be used to make multiple object instances
173
what is destructuring?
shortcuts for assigning properties to variables
174
how do you create destructured assignment with objects?
create a variable with the name of an object's key wrapped in curly brackets and assign it to the object const { object_key } = ___
175
what is called every time a new instance of a class is created?
the constructor( ) method
176
what is the difference between class and object syntax?
the constructor method (for classes)
177
what is an instance?
an object that contains property names and methods of class, but with unique property values
178
how the syntax for class methods and getters different from object syntax for methods and getters?
you can't use commas between class methods
179
is the syntax for calling methods and getters on an instance the same as calling them on an object?
yes
180
what is a parent class also known as?
a superclass
181
what are child classes also known as?
subclasses
182
when are classes candidates for inheritance?
when multiple classes share properties or methods
183
what does the super keyword do?
calls the constructor of the parent class
184
how do you avoid reference errors when creating classes using inheritance?
always call the super keyword method before using the this keyword
185
where is the super keyword placed in best practice?
on the first line of subclass constructors
186
what happens when extends is called on a class declaration?
all of the parent methods are available to that child class
187
can child classes have their own properties, getters, setters, and methods outside of those they inherit?
yes
188
what are static methods?
methods that aren't available in individual instances, but that can be called directly from the class
189
you cannot call static methods on a ___
instance
190
how do you define a class?
using a class declaration
191
in what HTML element is JavaScript encapsulated in?
< script >
192
what happens when an HTML parser comes across JavaScript
it stops to load the JS content before parsing the rest of the HTML
193
what are web events?
user interactions and browser manipulations that you can program to trigger functionality
194
what is the returned value of a function without a return statement?
undefined
195
what is a queue in computer science?
an abstract data structure where items are kept in order
196
what do comparison operators return?
a boolean true or false
197
what is the difference between === and ==
``` === is strict equality == is the equality operator ```
198
if values being compared by a strict equality operator have different types, they are considered ___
unequal (will return false)
199
what happens when values being compared by the equality operator (==) are not the same type?
the equality operator performs a type conversion and the evaluates the values
200
what is this !== operator called
the strict inequality operator
201
what is this operator: | |
the logical or operator
202
what does the logical or operator ( ||) do?
returns true if either of the operands is true, otherwise it returns false
203
what do switch statements do?
they test a value and can have many case statements which define various possible values - statements are executed from the first matched case value until a break is encountered
204
how are case values tested in a switch statement?
with strict equality (===)
205
what does a default statement within a switch statement do?
the default statement is executed if no matching case statements are fond
206
where should the default statement go in a switch statement?
at the end (like an else statement)
207
what happens when a return statement is reached within a function?
the execution of the current function stops
208
how do you separate items within an object
with a comma ,
209
how many instances of a class does querySelector return?
just one
210
What would you use if you wanted to select all instances of something in DOM?
querySelectorAll
211
What is nodeList?
collections of nodes
212
what is a node?
a node is an abstract base class upon which many other DOM API objects are based - letting those object types to be used similarly and often interchangeably
213
what happens if you set setTimeout to 0
it still causes the event to be asynchronous