JavaScript Flashcards
What is the purpose of variables?
To store information
How do you declare a variable?
using var before the variable name
syntax
How do you initialize (assign a value to) a variable?
variableName = value
What characters are allowed in variable names?
alphabet, number, $ and _ (variable should not start with a number)
What does it mean to say that variable names are “case sensitive”?
uppercase and lowercase variable names are considered differently
What is the purpose of a string?
to store text information
What is the purpose of a number?
to store numbers
What is the purpose of a boolean?
to make a decision in a code (either true or false)
What does the = operator mean in JavaScript?
= means assigning value to a variable
How do you update the value of a variable?
variablename = newValue
What is the difference between null and undefined?
undefined variable means a variable has not been assigned any value by the user
null means variable is assigned by the user with a null value
Why is it a good habit to include “labels” when you log values to the browser console?
To know which variable is being printed is a console
Give five examples of JavaScript primitives.
number, string, boolean, symbol & bigint.
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
joining two separate strings to one
What purpose(s) does the + plus operator serve in JavaScript?
adding numbers or concating two or more string
What data type is returned by comparing two values (, ===, etc)?
Boolean data type
What does the += “plus-equals” operator do?
\+= means adding value and storing to same variable eg(variableName = VariableName + 'additionalString')
What are objects used for?
to store multiple data and different types of data
What are object properties?
variable store in object
Describe object literal notation.
eg {propert:value}
How do you remove a property from an object?
using delete operator followed by object.property
syntax (delete objectname.propertyname)
What are the two ways to get or update the value of a property?
dot notaion and bracket
eg
objectname.updateProperty = newValue
objectname[‘updateProperty’] = newValue
What are arrays used for?
To store a list of data of similar type
Describe array literal notation.
syntax arrayVariableName = [data1, data2, data_n];
How are arrays different from “plain” objects?
does not have key or property
What number represents the first index of an array?
zero 0
What is the length property of an array?
number of data in the array represent the length
How do you calculate the last index of an array?
arrayVariableName.length - 1
What is a function in JavaScript?
block od code that can be reused again and again
Describe the parts of a function definition.
function keyword, function name, parameter ,code block, and return
Describe the parts of a function call.
functionName(“argument-If-Any”)
When comparing them side-by-side, what are the differences between a function call and a function definition?
call would be without function keyword
What is the difference between a parameter and an argument?
the argument has actual value
Why are function parameters useful?
pass information or instructions into functions
What two effects does a return statement have on the behavior of a function?
Produce a value & exit the function
Why do we log things to the console?
to label the return
What is a method?
the method is a function on an object
How do you remove the last element from an array?
variableName.pop method
How do you round a number down to the nearest integer?
variableName.floor()
How do you generate a random number?
Math.random()
How do you delete an element from an array?
splice()
How do you append an element to an array?
push() unshift()
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?
no string is immutable and we can use console log to check
Roughly how many string methods are there according to the MDN Web docs?
a Lot of
Is the return value of a function or method useful in every situation?
its usefull but not in all case
Roughly how many array methods are there according to the MDN Web docs?
36 methods
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
What is the purpose of an if statement?
to make a decision on which blocks to run
Is else required in order to use an if statement?
no, it’s optional
Describe the syntax (structure) of an if statement.
if(condition)
{
code to execute
}
What are the three logical operators?
&&
||
!
How do you compare two different expressions in the same condition?
using( &&, ||, !)
What is the purpose of a loop?
to execute code over and over again
What is the purpose of a condition expression in a loop?
to check before executing a code block
What does “iteration” mean in the context of loops?
every time code runs within the {}
When does the condition expression of a while loop get evaluated?
before the iteration
When does the initialization expression of a for loop get evaluated?
only once
When does the condition expression of a for loop get evaluated?
before each express
When does the final expression of a for loop get evaluated?
every time until the condition became false
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?
Increment by one and assign it to variable
How do you iterate through the keys of an object?
using 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
What does the event.preventDefault() method do?
prevent the default behavior of elements
What does submitting a form without event.preventDefault() do?
refresh the page
What property of a form element object contains all of the form’s controls.
all elements within the forms
What property of form a 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?
its get more complicated if there is more line of code and gets hard to debug.
What is an advantage of having your console open when writing a JavaScript program?
to get insight of the code working
What is this in JavaScript?
it represet current object
What does it mean to say that this is an “implicit parameter”?
it present in every function and they dont need to declare
When is the value of this determined in a function; call time or definition time?
call time
What does this refer to in the following code snippet? var character = { firstName: 'Mario', greet: function () { var message = 'It\'s-a-me, ' + this.firstName + '!'; console.log(message); } };
nothing function in not called yet
Given the above character object, what is the result of the following code snippet? Why?
character.greet();
it’s-a-me Mario
Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello();
undefined
How can you tell what the value of this will be for a particular function or method definition?
we cant know
How can you tell what the value of this is for a particular function or method call?
function call will have window as this while methods will have object name of that method as this
What kind of inheritance does the JavaScript programming language use?
prototypeOf inheritance
What is a prototype in JavaScript?
its the predefined object which we can reuse
How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on objects, arrays, and numbers?
bcas of prototype object
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
it will look into object prototype
What does the new operator do?
The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
What does the instanceof operator do?
The instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.
What is a “callback” function?
is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.
Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?
setTimeout()
How can you set up a function to be called repeatedly without using a loop?
setInterval()
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0, it will immediately run the function
What do setTimeout() and setInterval() return?
The returned intervalID is a numeric, non-zero value which identifies the timer created by the call to setInterval() or setTimeout();
What is AJAX?
ajax is a technique for loading data into part of a page without having to refresh the entire page
What does the AJAX acronym stand for?
Asynchronous JavaScript And XML
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest()
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load event
Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
it share the prototype
Array.prototype.filter
The filter() method is an immutable JavaScript array iteration method that creates a new array filled with all the original array elements that pass the test provided by the callback function without changing the original array.
Array.prototype.map
The method map of the Array prototype allows you to grab a hold of each element inside an array and apply a function to them.
Array.prototype.reduce
The Array.prototype.reduce() method is an immutable JavaScript array iteration method that executes a callback function on each element of the array, resulting in a single output value.
What is “syntactic sugar”?
make easy to read
What is the typeof an ES6 class?
function
Describe ES6 class syntax.
class classname { methodname() { } }
What is “refactoring”?
reconstructing the code
How are ES Modules different from CommonJS modules?
import and export keyword vs required and module.export
What kind of modules can Webpack support?
ECMAScript modules CommonJS modules AMD modules Assets WebAssembly modules
What does fetch() return?
return promise which is fulfilled once the response is available.
What is the default request method used by fetch()?
GET
How do you specify the request method (GET, POST, etc.) when calling fetch?
eg fetch('https://example.com/profile/avatar', { method: 'PUT', body: formData })
When does React call a component’s componentDidMount method?
componentDidMount() is invoked immediately after a component is mounted (inserted into the tree). Initialization that requires DOM nodes should go here. If you need to load data from a remote endpoint, this is a good place to instantiate the network request.
Name three React.Component lifecycle methods.
constructor()
render()
componentDidMount()
How do you pass data to a child component?
passing through props
What must the return value of myFunction be if the following expression is possible?
myFunction()();
return innerfunction value.
What does this code do? const wrap = value => () => value;
wrap return an anonymous function that return the wrap function parameter.
In JavaScript, when is a function’s scope determined; when it is called or when it is defined?
when it is defined.
What allows JavaScript functions to “remember” values from their surroundings?
Closures.