Javascript Flashcards
What is JavaScript?
JavaScript allows us to create incredibly diverse applications that run in the browser, on the back-end as NodeJS, on the desktop, and on mobile devices. It’s a flexible language, allowing us to program in many different styles — functional and object-oriented, in particular — mixing and matching concepts to adapt to our needs. It’s powerful, scalable, and has a robust community of developers churning out new code and advancing the language. And, finally, it’s a great first or second language to learn.
What are variables?
- Hold primitive or compound data
- Types: Let & Const
What is Let?
- Declares variable that can be changed later
What is Const?
- Variable that cannot be changed
What are the 2 types of data? (2)
- Primitive
- Compound
What are the 2 types of data? (2)
- Primitive
- Compound
What is Compound data?
- array
- object
Define DOM
- Document Object Model
What is the DOM?
__
How to write an IF statement in JS
__
How to insert JS?
- Insert tag just before </body> of HTML doc containing link to .js file.
- real-life apps bundle many .js files into one
What is asynchronous JS?
- The process of making requests for additional data from a loaded page
Define AJAX
- Asynchronous JavaScript and XML
How to write an IF statement in JS
if (condition) { // Block of code }
What is ECMAScript?
- JavaScript specification revised every yr since ES2015-ES2020
How can I manipulate the DOM with JS?
- Open Chrome DevTools with Ctrl+Shift+J & open the JS Console
What is a strict equality operator? (ex)
- returns true if two values are equal without performing type conversions
- 42 === 42
true - strict inequality operator is !==
How to write an ELSE statement in JS
const age = 14;
let isAdult;
if (age >= 18) { isAdult = true; } else { isAdult = false; } // => false
isAdult; // => false
How to write an ELSE IF statement in JS
const age = 20;
let isAdult, canWork, canEnlist, canDrink;
if (age >= 21) { isAdult = true; canWork = true; canEnlist = true; canDrink = true; } else if (age >= 18) { isAdult = true; canWork = true; canEnlist = true; } else if (age >= 16) { canWork = true; } // => true
isAdult; // => true
canWork; // => true
canEnlist; // => true
canDrink; // => undefined
How to write a SWITCH statement in JS
const hunger = ‘famished’;
let food;
switch (hunger) { case 'light': food = 'grapes'; break; case 'moderate': food = 'sushi'; break; case 'famished': food = 'lasagna'; break; } // => "lasagna"
food; // => "lasagna"
Ternary operator example
const age = 60;
const isAdult = age >= 18 ? true : false;
isAdult; // => true
How to write a function in JS?
function functionName(argument1, argument2, argument3) { body code goes here }
Objects
https://learn.co/tracks/cpb-v5/javascript/data-structures/objects
For Loop
for (let i = 0; i < array.length; i++) { // Loop body }
While
while (j < myArray.length) {
console.log(myArray[j++]);
}
How to iterate over an array
Use a for…of statement anytime you want to iterate over an array.
How to iterate over an object
for (const in ) { // Code in the statement body }
Traverse nested objects
userInfo.friends[0].firstName; // => "Joe"
Filter
[1, 2, 3, 4, 5].filter(function (num) { return num > 3; }); // => [4, 5]
.map( )
const equippedEngineers = newEngineers.map(function(eng) { return Object.assign({}, eng, { equipment: 'Laptop' }); });
equippedEngineers; // => [ // { userID: 15, title: "Developer Apprentice", accessLevel: "admin", equipment: "Laptop" }, // { userID: 63, title: "Developer Apprentice", accessLevel: "admin", equipment: "Laptop" }, // { userID: 97, title: "Developer Apprentice", accessLevel: "admin", equipment: "Laptop" }, // { userID: 12, title: "Developer Apprentice", accessLevel: "admin", equipment: "Laptop" }, // { userID: 44, title: "Developer Apprentice", accessLevel: "admin", equipment: "Laptop" } // ]