JavaScript

Getting Started

Introduction

JavaScript is a lightweight, interpreted programming language.

  • JSON cheatsheet

  • Regex in JavaScript

Console

// => Hello world!
console.log('Hello world!');

// => Hello Vietelligent.ME
console.warn('hello %s', 'Vietelligent.ME');

// Prints error message to stderr
console.error(new Error('Oops!'));

Numbers

let amount = 6;
let price = 4.99;

Variables

Strings

Arithmetic Operators

Comments

Assignment Operators

String Interpolation

let Keyword

const Keyword

JavaScript Conditionals

if Statement

Ternary Operator

Operators

Logical Operator &&

Comparison Operators

Logical Operator !

Nullish coalescing operator ??

else if

switch Statement

== vs ===

The == just check the value, === check both the value and the type.

JavaScript Functions

Functions

Anonymous Functions

Arrow Functions (ES6)

With two arguments

With no arguments

With a single argument

Concise arrow functions

Arrow function available starting ES2015

return Keyword

Calling Functions

Function Expressions

Function Parameters

Function Declaration

JavaScript Scope

Scope

Block Scoped Variables

Global Variables

let vs var

var is scoped to the nearest function block, and let is scoped to the nearest enclosing block.

Loops with closures

The variable has its own copy using let, and the variable has shared copy using var.

JavaScript Arrays

Arrays

Property .length

Index

Mutable chart

add
remove
start
end

push

pop

unshift

shift

Method .push()

Add items to the end and returns the new array length.

Method .pop()

Remove an item from the end and returns the removed item.

Method .shift()

Remove an item from the beginning and returns the removed item.

Method .unshift()

Add items to the beginning and returns the new array length.

Method .concat()

if you want to avoid mutating your original array, you can use concat.

JavaScript Loops

While Loop

Reverse Loop

Do…While Statement

For Loop

Looping Through Arrays

Break

Continue

Nested

for...in loop

for...of loop

JavaScript Iterators

Functions Assigned to Variables

Callback Functions

Array Method .reduce()

Array Method .map()

Array Method .forEach()

Array Method .filter()

JavaScript Objects

Accessing Properties

Naming Properties

Non-existent properties

Mutable

Assignment shorthand syntax

Delete operator

Objects as arguments

Shorthand object creation

this Keyword

Factory functions

Methods

Getters and setters

JavaScript Classes

Static Methods

Class

Class Constructor

Class Methods

extends

JavaScript Modules

Export

Import

Export Module

Require Module

JavaScript Promises

Promise states

Executor function

setTimeout()

.then() method

.catch() method

Promise.all()

Avoiding nested Promise and .then()

Creating

Chaining multiple .then()

Fake http Request with Promise

JavaScript Async-Await

Asynchronous

Resolving Promises

Async Await Promises

Error Handling

Aysnc await operator

JavaScript Requests

JSON

Also see: JSON cheatsheet

XMLHttpRequest

XMLHttpRequest is a browser-level API that enables the client to script data transfers via JavaScript, NOT part of the JavaScript language.

GET

POST

fetch api

JSON Formatted

promise url parameter fetch api

Fetch API Function

async await syntax

Last updated