JS Flashcards
What is a variable?
JS variables are containers for storing data values.
Why are variables useful?
Because we can change the value of a variable and can reuse them as well. Also useful for readability!
What two special characters can a variable begin with?
$ and _
How do you declare a variable?
You can do: var variable name
How do you assign a value to a variable?
variable name = value you want to assign
Are variables case sensitive?
Yes
Which words cannot be used as variable names?
reserved words (JS keywords)
What is a string?
A JS String stores a series of characters like “Tia Kim”.
What is the string concatenation operator?
It produces a new string by appending the second operand onto the end of the first operand.
What is the difference when it comes to using single quotes or double quotes ( ‘ ‘ or “ “ )?
No difference.
How do you escape quotation characters?
You can use \ to escape quotation characters.
What is type coercion?
Type coercion is the process of converting value from one type to another.
What is a number in JavaScript?
It represents and manipulate numbers.
What is an arithmetic operator?
It takes numerical values as their operands and return a single numerical value.
Name four of the arithmetic operators?
+, -, /, *
What is the order of execution?
Multiplication and division are performed before addition or subtraction.
What is a boolean?
Boolean is a data type that returns either true or false.
What is a comparison operator?
A comparison operator compares its operands and returns a Boolean value based on whether the comparison is true.
What is the difference between undefined and null?
Undefined is a type and null is an object.
What advantages do you see with using a grid system?
Easier to stay organized with the layout,
mobile responsiveness, consistency, etc.
What is a function?
A function is a block of code that performs a particular task.
Why are functions useful?
Because you can use it multiple times with different arguments.
How do you call a function?
With its name followed by parentheses.
What are the parts of a function definition?
Function keyword, function name, code block.
Parameters vs arguments
Parameters are the names listed in the function definition and arguments are the real values that are passed to the function.
Why is it important to understand truthy and falsy values?
Because it is important when writing conditional statements in code.
Why is the typeof null an object?
It’s a bug.
What is the difference between null and undefined?
Undefined is a variable that has been declared but not assigned a value and null is assigned and means empty.
Why do you always use === for comparisons?
Because it doesn’t do type coercion so it can prevent you from doing unexpected type coercion.
What is the primary use case for switches?
When you want to compare one value with multiple values, you use switch statement.
Does the default case have to be at the bottom of the switch statement?
By convention, the default clause is the last clause, but it does not need to be so.
What happens if there is no break statement between cases?
The program will run statements from the matching case to the end of the line.
What is an object in JavaScript?
An object groups a set of variables and functions together.
What is a property in relation to JavaScript objects?
A property of an object is a variable that is attached to the object.
When should you use bracket notation over dot notation with objects?
When the property’s name is in numbers.
When should you use bracket notation over dot notation with objects?
When the property’s name is in numbers or includes spaces or if you have a variable that you need to substitute.
What is an array in JavaScript?
It stores a list of values in a single variable.
How do you create an array literal?
You can create it with square brackets.
What are the keys for the values inside an array?
The index.
Arrays have a property named length. Because arrays have a properties, what other data structure are they similar to?
Object.
What is the primary advantage to storing your selected elements in a variable?
You can re-reference to the element without having the browser to look through the DOM tree to find the same element again.
Why might you need JavaScript to modify the DOM after the page loads?
To be interactive with a user. Also we can update the content of the web page in a more efficient way.
How can you better prepare when writing HTML for DOM manipulation in your JavaScript code?
Create IDs, classes, etc.
Why is the Window.event property useful for finding an element which was interacted with?
Because it tells you which event is happening - if it’s a mouse event then you can guess that maybe something was clicked
Why is the Window.event property to be avoided in new code?
?
Who passes in the event object into the handleClick callback function?
Javascript!
What is jQuery?
jQuery is a JS library designed to simplify HTML DOM tree traversal and manipulation, as well as event handling, CSS animation, and Ajax.
What is the jQuery selector function?
It is a function which makes use of expressions to find out matching elements from a DOM based on the given criteria.
What does the jQuery selector function return?
It returns a collection of matched elements either found in the DOM based on the passed arguments or created by passing an HTML string.
What are some downsides from using jQuery over vanilla Javascript?
The library is huge to download?
Why do we use the tag at the bottom of the body, instead of putting it inside the <head> tag?
If we put the script tag at the bottom of your html body, it gives the html time to load before any of the js loads, so it prevents from having errors and speed up website response time.
What is event bubbling?
Event bubbling is a type of event propagation where the event first triggers on the innermost target element, and then successively triggers on the ancestors of the target element in the same nesting hierarchy till it reaches the outermost DOM element or document object.
(It’s a type of event propagation where the most specific node gets triggered first and then the event flows outwards to the least specific ones)
What is the difference between event.target and event.currentTarget.
event.currentTarget tells you where the event is attached to and event.target tells you where the user clicked on.
What is the first argument the function setTimeout takes?
A function that is going to be executed after the timer expires.
What does the setInterval function return?
It returns an intervalID which is a numeric, non-zero value which identifies the timer created by the call to setInterval().
What is a call stack?
A call stack is a mechanism for an interpreter to keep track of its place in a script that calls multiple functions.
(It’s where JS keeps track of all the operations in line to be executed)
What is the event loop?
It’s a programming design patter that waits for and dispatches events or messages in a program.
(It looks at the call stack and the call back queue, and if the call stack is empty it will take the first event from the queue and push it to the call stack)
What does the term blocking mean?
It’s when something(render queue) blocks events in the queue to be moved over to the stack.
What is a method?
A method is a function which is a property of an object.
What does a method do?
Whatever the code inside the block tells you to do
What does the new keyword do?
The new operator lets developers create an instance of a user-defined object type or one of the built-in object types that has a constructor function.
I could’ve added a method to the constructor function by assigning a method to a property on the this object. Why do we have to add it to the prototype property?
To save memory space
What is the first thing that happens in a class when it is instantiated with the new keyword?
It creates a blank, plain JS object -> Links (sets the constructor of) this object to another object -> Passes the newly created object from step 1 as the this context -> Returns this if the function doesn’t return an object
Difference between functions vs classes?
Function declarations are hoisted and class declarations are NOT.
What is a static method?
Static methods CANNOT be called through a class instance. They are called without instantiating their class. Often used to create utility functions for an application.
What is the benefit of instantiating Classes within other classes?
You can inherit their constructor and don’t have to re-write the same code lines. Also when there is a tie between the classes.
What is the basic idea of OOP?
The idea is to model real world things that we want to represent inside our code.