Javascript Flashcards
what is the purpose of variables?
to declare a value.
to store info to be referenced
how do you declare a variable?
using var, let, const keyword
how do you initialize ( assign a value to ) a variable?
add an equal sign and put the value
what characters are allowed in variable names?
No other characters are permitted in the variable name. Specifically, spaces are not permitted in the variable names, as variable name must be a single word. Variable name may not start with a digit or underscore, and may not end with an underscore. Double underscores are not permitted in variable name.
what does it mean to say that variable names are “case sensitive”?
Uppercase and lowercase letters are treated as distinct
what is the purpose of a string?
to store or indicate text value
what is the purpose of a number?
to store or indicate numerical value
what is the purpose of a boolean?
to store or indicate true/false value
what does the = operator mean in javascript?
assigning a value
how do you update the value of a variable?
by assigning a different value that you want
what is the difference between null and undefined?
a null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address.
undefined is that, there’s no value in it.
why is it a good habit to include “labels” when you log values to the browser console?
to make debugging easier.
Five examples of javascript primitives
string, number, boolean, null, undefined
what data type is returned by an arithmetic operation?
- numeric data type
what is string concatenation?
- connecting strings by using +. combining strings.
- strings are immutable in javascript. (not mutable, it cannot change)
what purpose does the + plus operator serve?
concatenating strings or add numeric values with arithmetic operators.
what data type is returned by comparing two values?
boolean
what does the += plus equals operator do?
add value to the variable and store the value in the same variable
what are objects used for?
JavaScript objects are containers for named values, called properties and methods.
what are object properties?
association between key and value
Describe object literal notation
The Object literal notation is basically an array of key:value pairs, with a colon separating the keys and values, and a comma after every key:value pair, except for the last, just like a regular array.
- opening and closing curly brases
how do you remove a property from an object?
by using the delete keyword
what are the two ways to get or update the value of a property?
adding keys by using dot notation or add inside the object directly.
what are arrays used for ?
it is used for storing different elements
describe array literal notation
array literal notation is where you define a new array using just empty brackets.
how are arrays different from “plain” objects?
you can get values by indicating the index.?
- doesnt need a name key.
- have a property name length and is automatically updated when adding a new value.
- list .
what number represents the first index of array?
0
what is the length property of an array?
get the total number of values
how do you calculate the last index of an array?
total length - 1
what is a function in javascript?
a block of code designed to perform a particular task.
describe the parts of a function definition
the function keyword, an optional name, a comma-separated list of zero or more parameters, surrounded by parentheses. The start of the function’s code block, an optional return statement. the end of the function’s code block.
describe the parts of a function call
write the function name and parentheses next to it. pass an argument to the function
describe the parts of a function call
write the function name and parentheses next to it. pass an argument to it?
what are the differences between a function call and a function definition?
calling a function means executing it.
what is the difference between a parameter and an argument?
Parameter is variable in the declaration of function.
Argument is the actual value of this variable that gets passed to function.
why are function parameters useful?
A function can take parameters which are just values you supply to the function so that the function can do something utilising those values.
reusing values for other purposes?
what two effects does a return statement have on the behavior of a function?
The return statement ends function execution and specifies a value to be returned to the function caller
why do we log things to the console.?
to see the result value and for debugging
what is the method?
method is a function which is a property of an object
how is a method different from any other function?
function themselves are objects, so, in that context, a method is actually an object reference to a function.
How do you remove the last element from an array?
use the pop() method.
how do you round a number down to the nearest integer?
Math.floor() bring it down to the nearest integer.
how do you generate a random number?
Math.random()
How do you delete an element from an array?
splice(start, deleteCount, item1)
how do you append an element to an array?
push()
how do you break a string up into an array?
split()
do string methods change the original string? how would you check if you weren’t sure?
All string methods return a new string. They don’t modify the original string. Formally said: Strings are immutable: Strings cannot be changed, only replaced.
roughly how many string methods are there according to the MDN web docs?
45-50 methods.
is the return value of a function or method useful in every situation?
sometimes. push() method is just to add an element to the array
roughly how many array methods are there according to the MDN web docs?
many many
what three letter acronym should you always include in your google search about a javascript method or css property?
MDN
Give six examples of comparison operators.
, ===, ==, >=, <=, !==
what data type do comparison expressions evaluate to?
boolean, true or false
what is the purpose of an ‘if’ statement?
to declare a condition within the function