Javascript Flashcards
What is the purpose of variables?
to store data for the future.
How do you declare a variable?
utilizing the var keyword to declare it.
How do you initialize (assign a value to) a variable?
You assign the variable name (identifier) to a value using a single = sign.
What characters are allowed in variable names?
letters, underscore, start with $ or underscore camelCased capitalized letters but numbers cant be in the front.
What does it mean to say that variable names are “case sensitive”?
that the same variable name but with different casing have different variable names.
What is the purpose of a string?
how to hold a sequence of data characters of characters of numbers letters and other characters
What is the purpose of a number?
to store number mainly for math
What is the purpose of a boolean?
to compare expressions as true or false.
What does the = operator mean in JavaScript?
assignment operator.
How do you update the value of a variable?
you set the variable name without the keyword to another variable value
What is the difference between null and undefined?
null is the intentional absence of value where it is an object. it can be assigned but not output by java. but undefined does not have a value assigned to a variable. 1) null get data later or it was never going to be added and you will know. Java outputs undefined so developers should not.
Why is it a good habit to include “labels” when you log values to the browser console?
logging the value without the label makes it unknown what it is being used and where it comes from.
Give five examples of JavaScript primitives.
str, num, undefined, boolean, null
What data type is returned by an arithmetic operation?
numbers
What is string concatenation?
when you combine strings utilizing , or + as any other data type becomes a string
What purpose(s) does the + plus operator serve in JavaScript?
Addition or concatenation
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
it sets the value of the left side as it self plus what is on the right side
What are objects used for?
objects group together different variables datatypes can group multiple properties in association of the same object as well as being able have multiple similar object with differing properties be better organized.
What are object properties?
piece of data stored in object. easiest method to notate objects with curly brackets being assigned to a variable. with key vales.
Describe object literal notation.
defining the object and assigning to a curly brackets with a property key name : value
How do you remove a property from an object?
delete object.property
What are the two ways to get or update the value of a property?
through appending or using the = operator to the property and giving a value.
Give 6 examples of comparison operators.
> =
<=
<
===
!=
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
to compare in a conditional.
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if condition {conditional block}
What are the three logical operators?
&& and
|| or
! not
How do you compare two different expressions in the same condition?
using logical operators
Why do we log things to the console?
for debugging or to better understand how a process works.
What is a method?
it is a function within an object
How is a method different from any other function?
its is held within an object
How do you remove the last element from an array?
array.pop
How do you round a number down to the nearest integer?
Math.floor
How do you generate a random number?
math.random float number between 0 and 1 representing a percentage
How do you delete an element from an array?
array.splice(index, how many)
How do you append an element to an array?
array.push
How do you break a string up into an array?
array.split(what it splits by) delimiter
Do string methods change the original string? How would you check if you weren’t sure?
no. console.log
Is the return value of a function or method useful in every situation?
no they have return values but you wont always use it
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
mdn
What is the purpose of a loop?
a way to run a code block until a specific condition is met
What is the purpose of a condition expression in a loop?
To top the loop from continue running
What does “iteration” mean in the context of loops?
how many times it will be running
When does the condition expression of a for loop get evaluated?
after the initialization
When does the final expression of a for loop get evaluated?
After each iteration
When does the condition expression of a while loop get evaluated?
before running the while loop
When does the initialization expression of a for loop get evaluated?
the beginning of the loop
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 value by 1 by default.
How do you iterate through the keys of an object?
for (keys in object) {
}
What event is fired when a user places their cursor in a form control?
focus
What event is fired when a user’s cursor leaves a form control?
blur
What event is fired as a user changes the value of a form control?
input
What event is fired when a user clicks the “submit” button within a <form>?
‘submit’ which is fired on the form and not the button. Never have the click event listener on a button
What does the event.preventDefault() method do?
preventing the default behavior. for check box it will not show a check. not common you want to rid the default
What does submitting a form without event.preventDefault() do?
if you dont call it, page reloads and refreshes. the data is on the url but irrelevant to the point. based on initial behavior of form behaviors and action attributes. default behavior would submit to same page.
What property of a form element object contains all of the form’s controls.
form.elements has certain properties. numbered properties, named properties in multiple forms. same thing is saved multiple times. email too message too. two out of three are saafety cases. dom is trying to pass it. have property based off of id attribute. user-email will show minus not the whole thing. using .email takes the name attribute. is relevant to form submissions. use a name attribute in every input using dot notation.
What property of a form control object gets and sets its value?
any form control containing the value property is get and set by VALUE
What is one risk of writing a lot of code without checking to see if it works so far?
if it doesn’t work, you wont know whats working and not working
What is an advantage of having your console open when writing a JavaScript program?
see if there are any errors.
Does the document.createElement() method insert a new element into the page?
no
How do you add an element as a child to another element?
parent.appendchild(child)
What do you pass as the arguments to the element.setAttribute() method?
assigned value to attribute
What steps do you need to take in order to insert a new element into the page?
create element then add textcontent if required then parent.appendchild(child)
make element, configure with class application or event listener, query for parent element, and then pass argument with appendchild.
What is the textContent property of an element object for?
assign value to textcontent
Name two ways to set the class attribute of a DOM element.
classname or set attribute or even set list.
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
What is the event.target?
it references the object to which an event happened
Why is it possible to listen for events on one element that actually happen its descendent elements?
bubbling allows its parents know which of its descendants are being listened to.
What DOM element property tells you what type of element it is?
event.target.tagName
What does the element.closest() method take as its argument and what does it return?
the closest item matching the argument string for css selector returning the nearest parent element with the css selector ancestor or null
How can you remove an element from the DOM?
element.remove()
If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?
event delegation by putting the event listener on the ancestor
What is the affect of setting an element to display: none?
makes the element not visible and not take any space.
What does the element.matches() method take as an argument and what does it return?
How can you retrieve the value of an element’s attribute?
At what steps of the solution would it be helpful to log things to the console?
every step
If you were to add another tab and view to your HTML, but you didn’t use event delegation, how would your JavaScript code be written instead?
If you didn’t use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?
What is JSON?
JSON is a text-based data format
What are serialization and deserialization?
Serialization is when code is being transcoded to bits and stored data whereas deserialization is taking the bits and stored data into real code
Why are serialization and deserialization useful?
To transmit information through the internet.