Skip to content

Latest commit

 

History

History
471 lines (339 loc) · 9.91 KB

File metadata and controls

471 lines (339 loc) · 9.91 KB

JavaScript Quick Syntax Reference


array

var myArray = [element1, element2, element3];
var myArray = new Array();

Learn on Treehouse

JavaScript Loops, Arrays, and Objects - What is an Array?

Practice on Treehouse

Practice Basic Arrays in JavaScript

arrow function

const addNumToTen = num => 10 + num;
const divideNumbers = (num1, num2) => num1/num2;
const printMyName = () => {
    const myName = 'Ashley';
    console.log(myName);
}

Learn on Treehouse

Introducing Arrow Function Syntax
Getting Started with ES2015 - Basic Arrow Syntax
Introducing ES2015 - Arrow Functions

Practice on Treehouse

Practice Arrow Functions in JavaScript on Treehouse

See also

function

bracket notation

object['propertyKey']
object['methodName']()
var propertyKey = 'name'
object[propertyKey] 
array[indexOfElement]

Learn on Treehouse

JavaScript Loops, Arrays, and Objects - Accessing Object Properties
Object-Oriented JavaScript - Dot Notation and Bracket Notation

See also

dot notation

class

class Fruit {

}

Learn on Treehouse

Introducing ES2015 - Structure of Class
Object-Oriented JavaScript - Writing Your First Class

See also

instance

const

const myString = 'Hello World';

Learn on Treehouse

Defining Variables with Let and Const
Introducing ES2015 - Let and Const
Getting Started with ES2015 - Declaring Variables in JavaScript

Practice on Treehouse

Practice Let and Const in JavaScript on Treehouse

See also

var
let

dot notation

object.propertyKey
object.methodName()

Learn on Treehouse

JavaScript Loops, Arrays, and Objects - Accessing Object Properties
Object-Oriented JavaScript - Dot Notation and Bracket Notation

See also

bracket notation

filter

array.filter(element => <condition>);

Learn on Treehouse

Array Iteration Methods - Remove Array Items with Filter

find

array.find(element => <condition>);

for

for (let i = 0; i <= 10; i++){
    console.log(i);
}

Learn on Treehouse

JavaScript Loops, Arrays, and Objects - For Loops

See also

forEach
for...in
for...of

forEach

myArray.forEach(function(elem){
    console.log(elem);
});

Learn on Treehouse

JavaScript Array Iteration - for vs forEach

Practice on Treehouse

Practice forEach in JavaScript

for...in

for (property in object) {
    console.log(`Key: ${prop}`); 
    console.log(`Value: ${object[prop]}`); 
}
See also

for
for...of

for...of

for (element of iterable) {
    console.log(element)
}
See also

for...in
for

function

function myFunc(param) {
    console.log(param);
}

Learn on Treehouse

JavaScript Basics - Introducing Functions

Practice on Treehouse

Practice Basic JavaScript Functions

See also

arrow functions

get

get myDynamicProperty(){
	return dynamicProperty;
}

Learn on Treehouse

Object-Oriented JavaScript - Getters

if

if (x == y) {
    console.log(true);
}

Learn on Treehouse

JavaScript Basics - Introducing Conditional Statements

Practice on Treehouse

Practice If and Else If Statements in JavaScript

See also

conditional
if else
if...else if
switch
ternary

if...else

if (x == y) {
    console.log(true);
} else (
    console.log(false);
)

Practice on Treehouse

Practice If and Else If Statements in JavaScript

See also

conditional
if
if...else if
switch
ternary

if...else if

if (x == y) {
    console.log(true);
} else if (x == j) (
    console.log(true);
) else {
    console.log(false);
}

Practice on Treehouse

Practice If and Else If Statements in JavaScript

See also

conditional
if
if...else
switch
ternary

instance

var banana = new Fruit();

Learn on Treehouse

Object Oriented JavaScript - Instantiating a Pet Object

See also

class

let

let myString = 'Hello World';

Learn on Treehouse

Defining Variables with Let and Const Introducing ES2015 - Let and Const Getting Started with ES2015 - Declaring Variables in JavaScript

Practice on Treehouse

Practice Let and Const in JavaScript on Treehouse

See also

const
var

loop

See also

for
for...in
for...of
while

Learn on Treehouse

JavaScript Loops, Arrays, and Objects - What are loops?

Practice on Treehouse

Practice JavaScript Loops

object literal

var object = {
    property1: "value1",
    property2: "value2",
    method1: function(){}
}

Learn on Treehouse

JavaScript Loops, Arrays, and Objects - The Object Literal
Object-Oriented JavaScript - Object Literals and Components of Objects

Practice on Treehouse

Practice Object Literals in JavaScript on Treehouse

return

return x;

switch

switch (x) {
    case 1:
        console.log(1);
        break;
    case 2:
        console.log(2);
        break;
    case 3: 
        console.log(3);
        break;
}

Learn on Treehouse

Exploring JavaScript Conditionals - Switch Statement

See also

conditional
if
if...else
if...else if
ternary

ternary

<condition> ? <code if true> : <code if false>;
x == y ? console.log('true') : console.log('false');
var val = x == y ? true : false;

Learn on Treehouse

Exploring JavaScript Conditionals - Ternary Operator

See also

conditional
if
if...else
if...else if
switch

var

var myString = 'Hello World';

Learn on Treehouse

JavaScript Basics - Introducing Variables

Practice on Treehouse

Practice Basic Variables, Input, and Output in JavaScript

See also

const
let

while

while (i < 10) {
    i++;
}

Learn on Treehouse

Javascript Loops, Arrays, and Objects - What are Loops?