click below
click below
Normal Size Small Size show me how
Intro to JavaScript
Question | Answer |
---|---|
What do variables do? | hold reusable data in a program and associate it with a name |
You can reassign a variable with "let"? | True |
const variables can be reassigned? | False |
How to interpolate values? | Using backticks `` and ${} |
What does the typeof keyword do? | returns the data type (as a string) of a value |
What does an If statement do? | checks a condition and will execute a task if that condition evaluates to true |
What does an If Else Statement do? | make binary decisions and execute different code blocks based on a provided condition |
How can you add more conditions to an If Else statement? | By using Else If statements |
what is this comparison operator "<"? | Less than |
what is this comparison operator ">"? | More than |
what is this comparison operator "<="? | Less than or equal to |
what is this comparison operator ">="? | Greater than or equal to |
what is this comparison operator "==="? | Is equal to |
what is this comparison operator "!=="? | Is not equal to |
what is this logical operator "&&"? | And |
what is this logical operator "||"? | Or |
what is this logical operator "!"? | Not |
Examples of Falsy data values | 0 , "" , null, undefined, NaN |
Example of a Ternary Operator | isCorrect ? console.log('Correct!') : console.log('Incorrect!'); |
What is a Ternary Operator? | Shorthand to simplify concise If Else statements |
What is the use of Switch Statements? | To simplify the process of writing multiple Else If statements |
What does the "break;" do | stops the remaining cases from being checked and executed |
Example of a Switch Statement | let athleteFinalPosition = 'first place'; switch (athleteFinalPosition){ case "first place" : console.log("You get the gold medal!"); break; default: console.log("No medal awarded.") break; } |
Example of an Else If statement | let stopLight = 'yellow'; if (stopLight === 'red') { console.log('Stop!'); } else if (stopLight === 'yellow') { console.log('Slow down.');} else { console.log('Caution, unknown!'); } |
Example of a Ternary Operator | let isNightTime = true; if (isNightTime) { console.log('Turn on the lights!'); } else { console.log('Turn off the lights!'); } |
Define Function | a reusable block of code that groups together a sequence of statements to perform a specific task |
Define Parameter | a named variable inside a function’s block which will be assigned the value of the argument passed in when the function is invoked |
Example of calling a function in code | greetWorld(); |
Example of function expressions | const calculateArea = function (width,height) { const area = width * height; return area; } |
Example of Arrow Function notation | const calculateArea = (width, height) => { const area = width * height; return area; } |
Example of single-block concise functions | const sumNumbers = number => number + number; |
Example of multi-block concise functions | const sumNumbers = number =>{ const sum = number + number; return sum; |
Define Scope | Where variables can be accessed through the program & determined by where & how they are declared |
Define Block | Statements that exist within {} |
Define Global Scope | Context within which variables are accessible to every part of the program |
Define Global Variables | Exist within the global scope |
Block Scope | Context within which variables are accessible, only within the block they are defined |
Define Local Variables | Exist within the block scope |
Define Global namespace | Space in our code that contains globally scoped info |
Scope pollution | Too many variables exist in a namespace or variables names are reused |
Define Arrays | Lists that store data in JS created with [] |
Each item inside of an array is at a numbered position, or index, starting at 0 True or False? | True |
Example of accessing an Array | myArray[0] |
Example of changing an item in an array | myArray[0] = "new string" |
How to see how many items in an Array | Using the .length property |
Arrays cant be nested inside other arrays. | False |
Purpose of Loops | Perform repetitive actions so we don't have to manually process the code every time |
Example of a For Loop | for (let counter = 0; counter < 4; counter++) { console.log(counter); } |
Example of Looping through an Array | const animals = ['Grizzly Bear', 'Sloth', 'Sea Lion']; for (let i = 0; i < animals.length; i++){ console.log(animals[i]); } |
Define Nested Loop | A loop running inside another loop |
Example of a Nested Loop | const myArray = [6, 19, 20]; const yourArray = [19, 81, 2]; for (let i = 0; i < myArray.length; i++) { for (let j = 0; j < yourArray.length; j++) { if (myArray[i] === yourArray[j]) { console.log('Both arrays have the number: ' + yourArray |
Examples of a Do While Loop | let counterTwo = 1; while (counterTwo < 4) { console.log(counterTwo); counterTwo++; } |
Example of a Do While Statement | let cupsOfSugarNeeded = 10 let cupsAdded = 0 do { cupsAdded++ console.log(cupsAdded + ' cup was added') } while (cupsAdded < cupsOfSugarNeeded); |
Purpose of Do While loops | Allow for different types of stopping conditions |