Flashcards › Technology & Coding › JavaScript
JavaScript Basics
Core JavaScript syntax, array methods and browser basics.
0 of 77 known
77 cards
- Print to the consoleTaskconsole.log('Hi')
- Declare a changeable variableTasklet x = 5;
- Declare a constantTaskconst PI = 3.14;
- Old way to declare a variableTaskvar x = 5;
- Single-line commentTask// comment
- Strict equalityTaska === b
- Strict inequalityTaska !== b
- Logical andTaska && b
- Logical orTaska || b
- Logical notTask!a
- RemainderTask7 % 2
- ExponentTask2 ** 3
- IncrementTaski++
- If statementTaskif (x > 3) { }
- Else ifTaskelse if (x === 3) { }
- Ternary operatorTaskcond ? a : b
- Switch statementTaskswitch (x) { case 1: break; }
- For loopTaskfor (let i = 0; i < 5; i++) { }
- For...of loopTaskfor (const item of arr) { }
- For...in loopTaskfor (const key in obj) { }
- While loopTaskwhile (x < 10) { }
- Function declarationTaskfunction add(a, b) { return a + b; }
- Arrow functionTaskconst add = (a, b) => a + b;
- Anonymous functionTaskfunction () { }
- Make an arrayTaskconst arr = [1, 2, 3];
- Add to end of arrayTaskarr.push(4)
- Remove last itemTaskarr.pop()
- Add to startTaskarr.unshift(0)
- Remove first itemTaskarr.shift()
- Array lengthTaskarr.length
- Loop over each itemTaskarr.forEach(x => ...)
- Transform every itemTaskarr.map(x => x * 2)
- Keep items that pass a testTaskarr.filter(x => x > 2)
- Combine into one valueTaskarr.reduce((sum, x) => sum + x, 0)
- Find first matchTaskarr.find(x => x > 2)
- Does the array include a value?Taskarr.includes(3)
- Sort an array (numbers)Taskarr.sort((a, b) => a - b)
- Join array into a stringTaskarr.join(', ')
- Make an objectTaskconst o = { name: 'Sam', age: 9 };
- Read an object propertyTasko.name or o['name']
- Get keys of an objectTaskObject.keys(o)
- Template literalTask`Hello ${name}`
- String lengthTasks.length
- String uppercaseTasks.toUpperCase()
- Split a stringTasks.split(' ')
- Convert to numberTaskNumber('5') or parseInt('5')
- Check not a numberTaskisNaN(x)
- Random number 0 to 1TaskMath.random()
- Round downTaskMath.floor(3.7)
- RoundTaskMath.round(3.5)
- Absolute valueTaskMath.abs(-3)
- Larger of valuesTaskMath.max(1, 5)
- UndefinedTaskA variable that has not been given a value
- NullTaskAn intentional empty value
- typeof operatorTasktypeof x
- Select an element by IDTaskdocument.getElementById('id')
- Select with a CSS selectorTaskdocument.querySelector('.cls')
- Change text of an elementTaskel.textContent = 'Hi'
- Change styleTaskel.style.color = 'red'
- Add a classTaskel.classList.add('on')
- Listen for a clickTaskel.addEventListener('click', fn)
- Wait before running codeTasksetTimeout(fn, 1000)
- Repeat code over timeTasksetInterval(fn, 1000)
- Fetch data from a URLTaskfetch(url)
- Parse JSON textTaskJSON.parse(text)
- Convert to JSON textTaskJSON.stringify(obj)
- PromiseTaskAn object for a value that will be available later
- async / awaitTaskSyntax for writing asynchronous code that reads in order
- Try/catchTasktry { } catch (e) { }
- Class definitionTaskclass Dog { constructor(name) { this.name = name; } }
- this keywordTaskRefers to the current object
- Import a moduleTaskimport x from './x.js';
- Export a functionTaskexport function f() { }
- Spread operatorTask[...arr]
- DestructuringTaskconst { a, b } = obj;
- JavaScript's creatorTaskBrendan Eich, in 1995
- Is JavaScript the same as Java?TaskNo, they are different languages
Download this deck
- CSVExcel, Google Sheets, Numbers
- Anki / Quizlet (tab-separated)Import straight into Anki or Quizlet
- JSONFor programmers and apps
- Plain textOne card a line, “front : back”, ready for Peabody's flashcard maker to print
Want paper cards? Paste the plain-text download into the flashcard maker.