Flashcards › Technology & Coding › JavaScript

JavaScript Basics

Core JavaScript syntax, array methods and browser basics.

77 cardsGrades 6–8, Grades 9–12, College, Adult#JavaScript#programming#web

0 of 77 known
77 cards
  • Print to the consoleTask
    console.log('Hi')
  • Declare a changeable variableTask
    let x = 5;
  • Declare a constantTask
    const PI = 3.14;
  • Old way to declare a variableTask
    var x = 5;
  • Single-line commentTask
    // comment
  • Strict equalityTask
    a === b
  • Strict inequalityTask
    a !== b
  • Logical andTask
    a && b
  • Logical orTask
    a || b
  • Logical notTask
    !a
  • RemainderTask
    7 % 2
  • ExponentTask
    2 ** 3
  • IncrementTask
    i++
  • If statementTask
    if (x > 3) { }
  • Else ifTask
    else if (x === 3) { }
  • Ternary operatorTask
    cond ? a : b
  • Switch statementTask
    switch (x) { case 1: break; }
  • For loopTask
    for (let i = 0; i < 5; i++) { }
  • For...of loopTask
    for (const item of arr) { }
  • For...in loopTask
    for (const key in obj) { }
  • While loopTask
    while (x < 10) { }
  • Function declarationTask
    function add(a, b) { return a + b; }
  • Arrow functionTask
    const add = (a, b) => a + b;
  • Anonymous functionTask
    function () { }
  • Make an arrayTask
    const arr = [1, 2, 3];
  • Add to end of arrayTask
    arr.push(4)
  • Remove last itemTask
    arr.pop()
  • Add to startTask
    arr.unshift(0)
  • Remove first itemTask
    arr.shift()
  • Array lengthTask
    arr.length
  • Loop over each itemTask
    arr.forEach(x => ...)
  • Transform every itemTask
    arr.map(x => x * 2)
  • Keep items that pass a testTask
    arr.filter(x => x > 2)
  • Combine into one valueTask
    arr.reduce((sum, x) => sum + x, 0)
  • Find first matchTask
    arr.find(x => x > 2)
  • Does the array include a value?Task
    arr.includes(3)
  • Sort an array (numbers)Task
    arr.sort((a, b) => a - b)
  • Join array into a stringTask
    arr.join(', ')
  • Make an objectTask
    const o = { name: 'Sam', age: 9 };
  • Read an object propertyTask
    o.name or o['name']
  • Get keys of an objectTask
    Object.keys(o)
  • Template literalTask
    `Hello ${name}`
  • String lengthTask
    s.length
  • String uppercaseTask
    s.toUpperCase()
  • Split a stringTask
    s.split(' ')
  • Convert to numberTask
    Number('5') or parseInt('5')
  • Check not a numberTask
    isNaN(x)
  • Random number 0 to 1Task
    Math.random()
  • Round downTask
    Math.floor(3.7)
  • RoundTask
    Math.round(3.5)
  • Absolute valueTask
    Math.abs(-3)
  • Larger of valuesTask
    Math.max(1, 5)
  • UndefinedTask
    A variable that has not been given a value
  • NullTask
    An intentional empty value
  • typeof operatorTask
    typeof x
  • Select an element by IDTask
    document.getElementById('id')
  • Select with a CSS selectorTask
    document.querySelector('.cls')
  • Change text of an elementTask
    el.textContent = 'Hi'
  • Change styleTask
    el.style.color = 'red'
  • Add a classTask
    el.classList.add('on')
  • Listen for a clickTask
    el.addEventListener('click', fn)
  • Wait before running codeTask
    setTimeout(fn, 1000)
  • Repeat code over timeTask
    setInterval(fn, 1000)
  • Fetch data from a URLTask
    fetch(url)
  • Parse JSON textTask
    JSON.parse(text)
  • Convert to JSON textTask
    JSON.stringify(obj)
  • PromiseTask
    An object for a value that will be available later
  • async / awaitTask
    Syntax for writing asynchronous code that reads in order
  • Try/catchTask
    try { } catch (e) { }
  • Class definitionTask
    class Dog { constructor(name) { this.name = name; } }
  • this keywordTask
    Refers to the current object
  • Import a moduleTask
    import x from './x.js';
  • Export a functionTask
    export function f() { }
  • Spread operatorTask
    [...arr]
  • DestructuringTask
    const { a, b } = obj;
  • JavaScript's creatorTask
    Brendan Eich, in 1995
  • Is JavaScript the same as Java?Task
    No, they are different languages

Download this deck

Want paper cards? Paste the plain-text download into the flashcard maker.