JavaScript Flashcards
what does the console keyword refer to?
an object, collection of data and actions that can be used in our code
how do you print in javascript?
console.log( ) ;
how do you write a single line comment in JavaScript?
with two forward dashes //
How do you write a multi-line comment in JavaScript?
/ *
- /
What are data types?
classifications given to different kinds of data used in programming
What are the 8 fundamental data types in JavaScript?
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
What are the data types number, string, boolean, null, undefined, and symbol referred to as?
primitive data types - the most basic data types in the JavaScript language
What is the difference between using console.log() to print numbers and text
text needs quotation marks around it within the brackets of console.log() whereas numbers do not
What is an operator in JavaScript?
a character that performs a task in the code
Give some arithmetic operators
\+ add - subtract * multiply / divide % remainder
What is the remainder operator sometimes called?
modulo (although it’s not quite a modulo)
What does the remainder operator do?
prints the remainder (returns the number that remains after the right hand number divides into the left hand number
What is the process of appending one string to another called?
concatenation
What property stores the number of characters in a string?
length
What are methods?
actions we can perform
What does math.floor() do?
takes a decimal and rounds it to the nearest whole number
what does math.random() do?
generates a random number between 0 to 1
What is a variable?
a container for a value that is stored in the computer’s memory
named storage for data
What can you do with variables?
create a variable with a descriptive name
store or update information stored in a variable
reference or ‘get’ information stored in a variable
what keywords can you use to declare variables?
let and const
What is the conventional way of capitalising in JavaScript called?
Camel Casing
How does camel casing work?
all words are grouped into one long word, the first word is not capitalised, then every word that follows is capitalised
myName
camelCaseEverything
what is the operator ‘ = ‘ called?
the assignment operator
what does the assignment operator do?
it assigns a value to a variable
Can variable names start with numbers?
no
are variable names case sensitive?
yes
can variable names be the same as keywords?
no
what does the let keyword signal?
that a variable can be reassigned a different value
what happens if you don’t give a variable a value?
it automatically has a value of undefined
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
What is the increment operator and what does it do?
the increment operator is ++ and it increases the value of the variable by 1
What is the decrement operator and what does it do?
the decrement operator is – and it decreases the value of a variable by 1
what does interpolate mean?
insert
What can you use the typeof operator for?
to check the data type of a variable
What is a code block / block statement indicated by in JavaScript?
curly brackets { }
What is this comparison operator? ‘ === ‘
the identity operator
What do all comparison statements evaluate to?
true or false
What are all comparison operators made up of?
two values that will be compared
an operator that separates and compares the values
What are the operators that work with booleans called?
logical operators
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
When would you use the && (the and) operator?
to check if two things are true
What can you do if only one condition needs to be true?
the || (pipe / or operator)
What does the ! (bang, not) operator do?
reverses/negates the value of a boolean
take a true or false value and return the opposite
What values are falsy?
0, empty strings, null, undefined, NaN (not a number)
When does JavaScript assign a truthy value in a boolean condition?
when you use the || pipe operator
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
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’);
Where does the ‘else if’ statement go?
After the if statement and before the else statement(s)
What can you use instead of a long list of ‘else if’ statements
switch
What should finish a case clause within switch?
break;
What is the syntax for switch?
switch (\_\_) { case '\_\_\_': console.log('\_\_\_\_'); break; //as many cases as need default: console.log('\_\_\_'); break;
what is a function?
a reusable block of code that groups together a sequence of statements to perform a specific task
give a way to create a function
with a function declaration
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 ( ) { }
what is the hoisting?
it allows access to declarations before they’re defined
is hoisting good practice?
no
when is the code inside a function executed
when it is called
How do you call a function?
type the function name followed by parentheses
functionName ()
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
parameters act as ___ for values inside a function
placeholders
when calling a function with parameters, we ___ the values in the parameters
specify
values that are passed to the function when it is called are called ___
arguments
how can arguments be passed to a function
as values (eg numbers) or as variables (eg recWidth, recHeight)
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
how do you pass back information from a function call?
with return, followed by the value you want to return
what happens if the value is omitted from return?
undefined is returned instead of the value wanted
what do you call functions being called within another function?
helper functions
what is usually omitted in a function expression?
function name
what is a function with no name called?
an anonymous function
how do you define a function inside an expression?
with the function keyword
what is the fat arrow notation?
=>
what do arrow functions do?
remove the need to type out the keyword function every time you need to create a function
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 {
}
when are parentheses required with function parameters?
when the function has more than one parameter
does a one line function need curly braces?
no
what is an implicit return?
when a single line function follow the fat arrow notation, removing the need for the return keyword
What is initialization?
assigning an initial value to a variable
What is common practice when assigning constant variables?
naming the variable in all uppercase, with an underscore between words
const FAV_PET =
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 _
how are arrays written?
inside square brackets [ ]
array indexes are __ based?
zero based, meaning that the first item is 0, second is 1, and so on
how are JS objects written?
with curly brackets {
}
what are function arguments?
values received by the function when it is invoked / called
what happens to a function when JS reaches a return statement?
the function stops executing
what operator invokes/calls a function?
the parentheses operator ( )