LearningFuze Mod 1 - Javascript Flashcards
What is the purpose of variables?
Variables are used to store information to be referenced and manipulated in a computer program.
How do you declare a variable?
assigning it with a value
How do you initialize (assign a value to) a variable?
by adding an equals (assignment operator) to the var
Ex (var=””)
What characters are allowed in variable names?
a letter a dollar sign $ or an underscore (_) or numbers but they CANNOT be in the start
What does it mean to say that variable names are “case sensitive”?
It relies on camelCase
What is the purpose of a string?
The String object is used to represent and manipulate a sequence of characters.
What is the purpose of a number?
Store numeric value
What is the purpose of a boolean?
it creates true or false statements
What does the = operator mean in JavaScript?
it assigns value
How do you update the value of a variable?
We write the variable name and giving a new value would change it
What is the difference between null and undefined?
undefined is a type by itself (undefined). … Here as the variable is declared but not assigned to any value, the variable by default is assigned a value of undefined. On the other hand, null is an object. It can be assigned to a variable as a representation of no value.
Why is it a good habit to include “labels” when you log values to the browser console?
Because if you do not assign a value it will make a global value and it can break it
Give five examples of JavaScript primitives.
undefined , null , boolean , string and number
What data type is returned by an arithmetic operation?
returns a single numerical value.
What is string concatenation?
joining two or more strings together to make one
What purpose(s) does the + plus operator serve in JavaScript?
It combines two strings and does addition
What data type is returned by comparing two values (
boolean, which is true or false statements
What does the += “plus-equals” operator do?
adds the value of the right operand to a variable and assigns the result to the variable.
What are objects used for?
Its used to model
What are object properties?
Is a variable
Describe object literal notation.
NEEDED
What are the two ways to get or update the value of a property?
.notion or bracket notion
What are arrays used for?
To store values
How are arrays different from “plain” objects?
They are numerical index
Describe array literal notation.
NEEDED
What is the length property of an array?
it records the values in the array
How do you calculate the last index of an array?
length of the array -1
What is a function in JavaScript?
Block of code and call as needed
Describe the parts of a function definition.
The function keyword, optional name, the perimeter list and the end of the code block
Describe the parts of a function call.
to call, we use the name (if it has one) and the parentheses
When comparing them side-by-side, what are the differences between a function call and a function definition?
NEEDED
What is the difference between a parameter and an argument?
NEEDED
Why are function parameters useful?
Stores data so the function can use
What two effects does a return statement have on the behavior of a function?
NEEDED
Why do we log things to the console?
To show the output in our javascript
What is a method?
A method is a function which is a property of an object.
How is a method different from any other function?
a method is associated with an object
How do you remove the last element from an array?
by using the pop method
How do you round a number down to the nearest integer?
by using the math.floor() method
How do you generate a random number?
by using .random() method
How do you delete an element from an array?
the pop method, shift method or the splice method
How do you append an element to an array?
the .push() method appends and the unshift method prepends it
Do string methods change the original string? How would you check if you weren’t sure?
No it will not change the original string and you can check it with the console log
Roughly how many string methods are there according to the MDN Web docs?
Around 30+
Is the return value of a function or method useful in every situation?
No
Roughly how many array methods are there according to the MDN Web docs?
Around 30+
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.
== is equal to, != is not equal to, > greater than, < less than, >= greater than or equal to, <= less than or equal to
What data type do comparison expressions evaluate to?
Boolean
What is the purpose of an if statement?
it makes checks on functions to do a certain action
What are the three logical operators?
&& logical and, || logical or, ! logical not
Describe the syntax (structure) of an if statement.
NEEDED
What is the purpose of a loop?
Run a block of code until a certain amount of time or the condition is met
What is the purpose of a condition expression in a loop?
the last thing we do before we start the code thats inside of the loop
What does “iteration” mean in the context of loops?
It’s the process of repeating the loop
When does the condition expression of a while loop get evaluated?
It’s before each time and after each iteration
When does the initialization expression of a for loop get evaluated?
One time before the loop begins
When does the condition expression of a for loop get evaluated?
Before each iteration
When does the final expression of a for loop get evaluated?
After the work of the conditional expression
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break; would be the keyword
What does the ++ increment operator do?
It increments by 1
How do you iterate through the keys of an object?
with a for in loop
What event is fired when a user places their cursor in a form control?
focus event
What event is fired when a user’s cursor leaves a form control?
blur event
What event is fired as a user changes the value of a form control?
Input event
What event is fired when a user clicks the “submit” button within a ?
submit event
What does the event.preventDefault() method do?
Cancels the event if its cancelable
What does submitting a form without event.preventDefault() do?
Submits it back to the page
What property of a form control object gets and sets its value?
Value property
What is one risk of writing a lot of code without checking to see if it works so far?
You can have an error in your code and you will have to dig to see what is wrong with it.
What is an advantage of having your console open when writing a JavaScript program?
Its useful to see if you are getting error messages