JavaScript Concepts Flashcards
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
its when you combine strings using the + operator
What purpose(s) does the + plus operator serve in JavaScript?
for numbers, it acts as the addition operator. 2+ 3 = 5
for strings, it acts as a concatenator
What data type is returned by comparing two values < , > , === , etc )?
boolean, either true or false
What does the += “plus-equals” operator do?
it is a shortcut command.
if word += 5 is the same as word = word + 5
What is the purpose of variables?
to assign a value for later reference. var area = 3 * 2
How do you declare a variable?
by using the keywords var , let , const
How do you initialize (assign a value to) a variable?
by using the = sign
What does it mean to say that variable names are “case sensitive”?
if the cases in the variable name are not matched exactly, an error will show
What does the = operator mean in JavaScript?
it is used to set values of variables
How do you update the value of a variable?
by using the variable name then the equal sign, followed by new value
What are objects used for?
a collection of properties where those properties can have their own values
What are object properties?
they are variable names that are attached to the object and they can have their values. The values can be different types but the properties are strings.
Describe object literal notation.
var obj = { }
How do you remove a property from an object?
delete nameOfObject.PropertyToDelete
What are the two ways to get or update the value of a property?
dot notation or bracket notation
What data type is returned by an arithmetic operation?
Numbers, including NaN since its type is number
What is string concatenation?
when you condense 2 or more strings into 1 string using the + operator
What purpose(s) does the + plus operator serve in JavaScript?
for strings it will be used to concatenate
for numbers it is used to add
for string + number it will concatenate by turning the number into a string
What is a function in JavaScript?
a formula, can be customized by you to take 0, 1, or more arguments. It will return a value., if you do not use return it will return undefined
Describe the parts of a function definition.
function key word, function name, parenthesis, and parameters (optional)
Describe the parts of a function call.
function name followed by (arguments here) example. greet('tom')
When comparing them side-by-side, what are the differences between a function call and a function definition?
function definition is just the code that you wrote, it will not run until it is called with ()
What is the difference between a parameter and an argument?
parameters are used when a function is declared. argument are the values that are passed into the parameters when the function is called
Why are function parameters useful?
you can use them as variables, which gives way more flexibility to do stuff
What two effects does a return statement have on the behavior of a function?
1) it ENDS the function when the JS engine finishes the return statement line
2) it returns a value from the function
What are arrays used for?
to have a collection of data by an ordered list, starting at index 0
Describe array literal notation
var = [] empty brackets mean array literal
How are arrays different from “plain” objects?
arrays do NOT have a property name and value. They have an index and a value. But like object, the value can be any type aka functions, objects, another array, number, string, etc
What number represents the first index of an array?
0
What is the length property of an array?
how many items it contains = the length
How do you calculate the last index of an array?
by using arrayName.length - 1
Why do we log things to the console?
to check our work during development phase
What is a method?
a function attached to an object as a property
How is a method different from any other function?
you must call it by calling the object first, using dot notation
How do you remove the last element from an array?
the pop method
How do you round a number down to the nearest integer?
use Math.floor(number here)
How do you generate a random number?
Math.random(numbers here) it is only from 0-.999999999999999999999
How do you delete an element from an array?
use the splice method, it is the 2nd argument
How do you append an element to an array?
by using splice or push
How do you break a string up into an array?
the split method
Do string methods change the original string? How would you check if you weren’t sure?
no they do not, you can console.log the original variable assigned the the original string to check
Roughly how many string methods are there according to the MDN Web docs?
40
Is the return value of a function or method useful in every situation?
most of the time yes
Roughly how many array methods are there according to the MDN Web docs?
about 35
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
Give 6 examples of comparison operators.
< > == === > = < =
What data type do comparison expressions evaluate to?
boolean so either true or false
What is the purpose of an if statement?
to check conditions
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if ( condition here ) {
code here
}
What are the three logical operators?
&& (and) || (or) ! (not)
How do you compare two different expressions in the same condition?
use either && or ||
What is the purpose of a loop?
to check values of collection 1 by 1, you can do something during those checks
What is the purpose of a condition expression in a loop?
the parameters for when the loop stops/runs
What does “iteration” mean in the context of loops?
cycling through each element/value
When does the condition expression of a while loop get evaluated?
at the start of the loop
When does the initialization expression of a for loop get evaluated?
at the start of the loop
When does the condition expression of a for loop get evaluated
after initialization
When does the final expression of a for loop get evaluated?
after the condition has ran
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
What does the ++ increment operator do?
increases the value of the variable attached by 1
How do you iterate through the keys of an object?
by using the for in loop
What is a method?
a function inside an obj
How can you tell the difference between a method definition and a method call?
definition is when it is being defined inside the function. A method call is requires dot notation to access the method inside the function
Describe method definition syntax (structure).
propertyName : function name( parameters) {
code block
}
Describe method call syntax (structure).
objName.Propertyname.methodName( )
How is a method different from any other function?
it is part of an object
What is the defining characteristic of Object-Oriented Programming?
writing procedural functions and storing them inside objects, which can then be accessed via dot notation
What are the four “principles” of Object-Oriented Programming?
Abstraction
Encapsulation
Inheritance
Polymorphism
What is “abstraction”?
being able to work with (possibly) complex things in simple ways
What does API stand for?
Application Programming Interface
What is the purpose of an API?
is a set of functions that allows applications to access data and interact with external software components, operating systems, or microservices