JAVASCRIPT Flashcards
What is the purpose of variables?
A script will have to temporarily store the bits of information it needs to do its job. It can store this data in variables.
Computers require more information than you think.
How do youdeclarea variable?
You need the variable keyword & variable name.
How do you initialize (assign a value to) a variable?
With the variable name, you need the assignment operator and variable value.
What characters are allowed in variable names?
Variable names can only contain letters, numbers, underscores, or dollar signs.
Variable name cannot start with a number.
What does it mean to say that variable names are “case sensitive”?
Capitalized letters vs lowercase letters are not the same value, meaning they make a difference and are “case sensitive”.
What is the purpose of a string?
Strings are made so that Javascript won’t read it as a code.
What is the purpose of a number?
Tasks that involve counting or calculating sums, numeric values.
What is the purpose of a boolean?
They are helpful when determining which part of a script should run.
What does the”=”operator mean in JavaScript?
It is the assignment operator. Assigns right operand value to left operand.
How do you update the value of a variable?
Re-write the new value on the right operand and declare it again.
The “var” keyword isn’t necessary for that second time.
What is the difference betweennullandundefined?
Null: It is the intentional absence of the value.
Null can’t be determined by Javascript.
Undefined: It meansthe value does not exist in the compiler.
Undefined can be determined by javascript.
Why is it a good habit to include “labels” when you log values to the browser console?
So you know what each value represents.
Easier for other people on your team who are also working on the same file.
Give five examples of JavaScript primitives.
String, number, boolean, null, undefined.
What data type is returned by an arithmetic operation?
A number data type.
What is string concatenation?
Joining together two or more strings to create one string, which is the string concatenation.
What purpose(s) does the”+”plus operator serve in JavaScript?
It can either add numbers, or join strings together like previous question.
It can also join variables together.
What data type is returned by comparing two values (,===, etc)?
A boolean data type.
What does the+=”plus-equals” operator do?
That operator adds the value of the right operand to a variable and assigns the result to the same variable on the left (this variable on the left will have a new value).
What are objects used for?
To keep a collection of related data, of primitive or reference types, in the form of “key: value” pairs.
What are object properties?
Properties are the values associated with a JavaScript object.
Describe object literal notation.
Opening and closing curly brace.
How do you remove a property from an object?
Use the delete operator.
“objectName”.”propertyName”
What are the two ways to get or update the value of a property?
Dot & Bracket Notation.
What are arrays used for?
When working on any kind of a list or with a set of values that are related to each other.
Describe array literal notation.
The square brackets.
How are arrays different from “plain” objects?
They hold a related set of key/value pairs like “plain” objects, but the key for each value is its index number.
Arrays don’t have individual named indexes.
What number represents the first index of an array?
0
What is thelengthproperty of an array?
It is a number that represents how many items are in that array.
How do you calculate the last index of an array?
“arrayName”.length - 1.
What is a function in JavaScript?
Packing up code for reuse throughout a program, making code “dynamic”: meaning that it can be written once to handle many (or eveninfinite!) situations.
Describe the parts of a functiondefinition.
- The name of the function.
- A list of parameters to the function, enclosed in parentheses and separated by commas.
- The JavaScript statements that define the function, enclosed in curly brackets.
- (usually) Return statement.
Describe the parts of a functioncall.
We are writing the name of the function and placing()parentheses next to it. This causes thecode blockwithin the function’sdefinitionto be executed.
It doesn’t always require arguments.
When comparing them side-by-side, what are the differences between a functioncalland a functiondefinition?
A function definition is longer because it actually contains the Javascript statement that defines the function. Calling the function just requires writing the name with or without an argument.
What is the difference between aparameterand anargument?
Parameter is what’s in the parentheses when the function is being defined, an argument is when it’s being called.
Why are functionparametersuseful?
With no parameters, the end result is always the same.
They pass values into functions.
What two effects does areturnstatement have on the behavior of a function?
A return statementends the execution of a function, and returns control to the calling function.
Why do we log things to the console?
It is a method for developers to write code to inconspicuously inform the developers what the code is doing. Only useful for developers!
Also, DEBUGGING.
What is a method?
Amethodis afunctionwhich is apropertyof anobject.
How is a method different from any other function?
Function is a set of logic that can be used to manipulate data. While, method is function that is usedto manipulate the data of the object whereit belongs.
How do you remove the last element from an array?
The pop() method.
How do you round a number down to the nearest integer?
The floor() method.
How do you generate a random number?
The random() method.
How do you delete an element from an array?
The splice() method.
How do you append (add to end) an element to an array?
The push() method.
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, strings are immutable.
To make sure, double check with console.log.
Roughly how many string methods are there according to the MDN Web docs?
45-50.
Is the return value of a function or method useful in every situation?
No.
For example, push() method already gives you a return value.
Roughly how many array methods are there according to the MDN Web docs?
40 to 50.
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 loosely equal to), != (is not equal to), === (strict equal to), > (greater than), >= (greater than or equal to), < (less than), <= (less than or equal to).
What data type do comparison expressions evaluate to?
Boolean data type.
What is the purpose of an”if”statement?
If statement evaluates & checks a condition. If the condition evaluates as true, any statements in the subsequent code block are executed.
Is”else”required in order to use anifstatement?
No.
Describe the syntax (structure) of anifstatement.
An “if” statement consists of the keyword ‘if’, followed by the condition written inside of the parentheses, an opening curly brace, a code to execute if the value is actually true, followed by the closing curly brace.
What are the three logical operators?
&& (logical and), || (logical or), ! (logical not).
How do you compare two different expressions in the same condition?
You use a comparison operator.
What is the purpose of a loop?
The purpose of loops isto repeat the same, or similar, code a number of times.
What is the purpose of aconditionexpression in a loop?
The condition is a boolean expression thatdetermines whether the ‘for’ should execute the next iteration.
“Should I stop?”
What does “iteration” mean in the context of loops?
The repetition of going through the condition.
Whendoes theconditionexpression of awhileloop get evaluated?
An expression evaluatedbefore each pass through the loop (iteration). If this condition evaluates as true, statement is executed. When condition evaluates to false, execution continues with the statement after the while loop.
Whendoes theinitializationexpression of aforloop get evaluated?
When the loop begins.
Whendoes theconditionexpression of aforloop get evaluated?
It is evaluatedbefore each iteration.
Whendoes thefinalexpression of aforloop get evaluated?
At the end of every loop iteration, before the condition runs again.
Besides areturnstatement, which exits its entire function block, which keyword exits a loop before itsconditionexpression evaluates tofalse?
Break.
What does the++increment operator do?
Adds one to the operand.
Returns a value.
If used postfix, with operator after operand (for example,x++), the increment operator increments and returns the value before incrementing.
If used prefix, with operator before operand (for example,++x), the increment operator increments and returns the value after incrementing.
How do you iterate through the keys of an object?
Using the “for in” statement.
Why do we log things to the console?
The console.log() is a function in JavaScript which isused to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user.
It’s used for debugging purposes.
What is a “model”?
A model is a replica of something else.
Which “document” is being referred to in the phrase Document Object Model?
Your HTML document.