{
 "source": "https://peabody.kids/flashcards/tech-javascript-basics",
 "id": "tech-javascript-basics",
 "title": "JavaScript Basics",
 "category": "technology",
 "subject": "JavaScript",
 "levels": [
  "6-8",
  "9-12",
  "college",
  "adult"
 ],
 "description": "Core JavaScript syntax, array methods and browser basics.",
 "tags": [
  "JavaScript",
  "programming",
  "web"
 ],
 "frontLabel": "Task",
 "backLabel": "JavaScript",
 "cards": [
  [
   "Print to the console",
   "console.log('Hi')"
  ],
  [
   "Declare a changeable variable",
   "let x = 5;"
  ],
  [
   "Declare a constant",
   "const PI = 3.14;"
  ],
  [
   "Old way to declare a variable",
   "var x = 5;"
  ],
  [
   "Single-line comment",
   "// comment"
  ],
  [
   "Strict equality",
   "a === b"
  ],
  [
   "Strict inequality",
   "a !== b"
  ],
  [
   "Logical and",
   "a && b"
  ],
  [
   "Logical or",
   "a || b"
  ],
  [
   "Logical not",
   "!a"
  ],
  [
   "Remainder",
   "7 % 2"
  ],
  [
   "Exponent",
   "2 ** 3"
  ],
  [
   "Increment",
   "i++"
  ],
  [
   "If statement",
   "if (x > 3) { }"
  ],
  [
   "Else if",
   "else if (x === 3) { }"
  ],
  [
   "Ternary operator",
   "cond ? a : b"
  ],
  [
   "Switch statement",
   "switch (x) { case 1: break; }"
  ],
  [
   "For loop",
   "for (let i = 0; i < 5; i++) { }"
  ],
  [
   "For...of loop",
   "for (const item of arr) { }"
  ],
  [
   "For...in loop",
   "for (const key in obj) { }"
  ],
  [
   "While loop",
   "while (x < 10) { }"
  ],
  [
   "Function declaration",
   "function add(a, b) { return a + b; }"
  ],
  [
   "Arrow function",
   "const add = (a, b) => a + b;"
  ],
  [
   "Anonymous function",
   "function () { }"
  ],
  [
   "Make an array",
   "const arr = [1, 2, 3];"
  ],
  [
   "Add to end of array",
   "arr.push(4)"
  ],
  [
   "Remove last item",
   "arr.pop()"
  ],
  [
   "Add to start",
   "arr.unshift(0)"
  ],
  [
   "Remove first item",
   "arr.shift()"
  ],
  [
   "Array length",
   "arr.length"
  ],
  [
   "Loop over each item",
   "arr.forEach(x => ...)"
  ],
  [
   "Transform every item",
   "arr.map(x => x * 2)"
  ],
  [
   "Keep items that pass a test",
   "arr.filter(x => x > 2)"
  ],
  [
   "Combine into one value",
   "arr.reduce((sum, x) => sum + x, 0)"
  ],
  [
   "Find first match",
   "arr.find(x => x > 2)"
  ],
  [
   "Does the array include a value?",
   "arr.includes(3)"
  ],
  [
   "Sort an array (numbers)",
   "arr.sort((a, b) => a - b)"
  ],
  [
   "Join array into a string",
   "arr.join(', ')"
  ],
  [
   "Make an object",
   "const o = { name: 'Sam', age: 9 };"
  ],
  [
   "Read an object property",
   "o.name or o['name']"
  ],
  [
   "Get keys of an object",
   "Object.keys(o)"
  ],
  [
   "Template literal",
   "`Hello ${name}`"
  ],
  [
   "String length",
   "s.length"
  ],
  [
   "String uppercase",
   "s.toUpperCase()"
  ],
  [
   "Split a string",
   "s.split(' ')"
  ],
  [
   "Convert to number",
   "Number('5') or parseInt('5')"
  ],
  [
   "Check not a number",
   "isNaN(x)"
  ],
  [
   "Random number 0 to 1",
   "Math.random()"
  ],
  [
   "Round down",
   "Math.floor(3.7)"
  ],
  [
   "Round",
   "Math.round(3.5)"
  ],
  [
   "Absolute value",
   "Math.abs(-3)"
  ],
  [
   "Larger of values",
   "Math.max(1, 5)"
  ],
  [
   "Undefined",
   "A variable that has not been given a value"
  ],
  [
   "Null",
   "An intentional empty value"
  ],
  [
   "typeof operator",
   "typeof x"
  ],
  [
   "Select an element by ID",
   "document.getElementById('id')"
  ],
  [
   "Select with a CSS selector",
   "document.querySelector('.cls')"
  ],
  [
   "Change text of an element",
   "el.textContent = 'Hi'"
  ],
  [
   "Change style",
   "el.style.color = 'red'"
  ],
  [
   "Add a class",
   "el.classList.add('on')"
  ],
  [
   "Listen for a click",
   "el.addEventListener('click', fn)"
  ],
  [
   "Wait before running code",
   "setTimeout(fn, 1000)"
  ],
  [
   "Repeat code over time",
   "setInterval(fn, 1000)"
  ],
  [
   "Fetch data from a URL",
   "fetch(url)"
  ],
  [
   "Parse JSON text",
   "JSON.parse(text)"
  ],
  [
   "Convert to JSON text",
   "JSON.stringify(obj)"
  ],
  [
   "Promise",
   "An object for a value that will be available later"
  ],
  [
   "async / await",
   "Syntax for writing asynchronous code that reads in order"
  ],
  [
   "Try/catch",
   "try { } catch (e) { }"
  ],
  [
   "Class definition",
   "class Dog { constructor(name) { this.name = name; } }"
  ],
  [
   "this keyword",
   "Refers to the current object"
  ],
  [
   "Import a module",
   "import x from './x.js';"
  ],
  [
   "Export a function",
   "export function f() { }"
  ],
  [
   "Spread operator",
   "[...arr]"
  ],
  [
   "Destructuring",
   "const { a, b } = obj;"
  ],
  [
   "JavaScript's creator",
   "Brendan Eich, in 1995"
  ],
  [
   "Is JavaScript the same as Java?",
   "No, they are different languages"
  ]
 ]
}
