Skip to content

Instantly share code, notes, and snippets.

@lorecrafting
Last active June 11, 2019 06:36
Show Gist options
  • Save lorecrafting/4d69396a401c2b1c8e9a435365928ada to your computer and use it in GitHub Desktop.
Save lorecrafting/4d69396a401c2b1c8e9a435365928ada to your computer and use it in GitHub Desktop.
Subset of Javascript that is recommended to commit to memory by all new programmers

Be able to write out these skeletons in less than five seconds. It is vital that these are committed to memory and you don't need to think about it when asked to create these.

  1. Defining a function
var aFunc = function(arg1, arg2) {
  // your code in function body here using arg1 and arg2
}
  1. Iterating over an array
for (var i = 0; i < array.length; i++) {
  // your code in loop body here using array[i]
}
  1. Looping from 0-10
for (var i = 0; i < 10; i++) {
  // your code here using i
}
  1. Looping over an object
for (key in object) {
  // your code here using key
}
  1. If statement
if(truthyStatement) {
  // do something here
} else if (someOtherTruthyStatement) {
  // otherwise do stuff in this block
} else {
  // otherwise default to do stuff in this block
}
  1. Array access
var myArray = [];
myArray.push('hello');
myArray.push(10);
console.log(myArray[0]);
console.log(myArray[1]);
  1. Object access
var myObject = {};
myObject['name'] = 'MyName';
console.log(myObject.name);

var myVar = 'age'
myObject[myVar] = 100;
console.log(myObject.age);

Methods to know about. You should be able to know what each of these does and quickly navigate documents to get the exact syntax.

  • Strings
    1. charAt()
    2. concat()
    3. contains()
    4. indexOf()
    5. length()
    6. search()
    7. splice()
    8. split()
    9. sub()
    10. substr()
    11. toLowerCase()
    12. toUpperCase()
  • Arrays
    1. join()
    2. length()
    3. pop()
    4. push()
    5. reverse()
    6. shift()
    7. unshift()
    8. slice()
    9. splice()
  • Objects
    1. Object.keys()
@lorecrafting
Copy link
Author

lorecrafting commented Mar 29, 2017

Be able to write out these skeletons in less than five seconds. It is vital that these are committed to memory and you don't need to think about it when asked to create these.

  1. Defining a function
var aFunc = function(arg1, arg2) {
  // your code in function body here using arg1 and arg2
}
  1. Iterating over an array
for (var i = 0; i < array.length; i++) {
  // your code in loop body here using array[i]
}
  1. Looping from 0-10
for (var i = 0; i < 10; i++) {
  // your code here using i
}
  1. Looping over an object
for (key in object) {
  // your code here using key
}
  1. If statement
if(truthyStatement) {
  // do something here
} else if (someOtherTruthyStatement) {
  // otherwise do stuff in this block
} else {
  // otherwise default to do stuff in this block
}
  1. Array access
var myArray = [];
myArray.push('hello');
myArray.push(10);
console.log(myArray[0]);
console.log(myArray[1]);
  1. Object access
var myObject = {};
myObject['name'] = 'MyName';
console.log(myObject.name);

var myVar = 'age'
myObject[myVar] = 100;
console.log(myObject.age);

Methods to know about. You should be able to know what each of these does and quickly navigate documents to get the exact syntax.

  • Strings
    1. charAt()
    2. concat()
    3. contains()
    4. indexOf()
    5. length()
    6. search()
    7. splice()
    8. split()
    9. sub()
    10. substr()
    11. toLowerCase()
    12. toUpperCase()
  • Arrays
    1. join()
    2. length()
    3. pop()
    4. push()
    5. reverse()
    6. shift()
    7. unshift()
    8. slice()
    9. splice()
  • Objects
    1. Object.keys()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment