JavaScript Basics CheatSheet

Variables

var variableName = value

Can be reassigned and are only available inside the function they are credited in. It’s Function scoped.

const variableName = value

Cannot be reassigned and not accessible before they appear within the code. Its block  scope.

Variables

let variableName=value

It can be reassigned but it’s similar to const i.e. block scoped.

If variables are not created inside a function or block they are globally  scoped.

What is a block ?

A block is a set of opening and closing curly brackets.

Basic Operators

+       Addition

–       Subtraction

*       Multiplication

/       Division

()     Grouping operator

%    Modulus (remainder)

++   increment numbers

– –    Decrement numbers

Functions

Normal Function

function name (parameter) {

// statements

}

Arrow Function

const name = (parameter) =>  {

// statements

}

Conditional Statements

If-Else Statements

if (condition) {

// code to be executed if the condition is true

} else {

//code to be  executed if the condition is false

}

Conditional Statements

Switch (expression) {

case X:

//code b1ock

break;

case y:

// code block

break;

default:

// code block

}

Truthy / Falsy Values
Falsy Values

  • false
  •  0 (zero)
  • null
  • undefined
  • NaN (not a number)

Truthy Values Everything that is not FALSY

String Escape Characters

\’      Single quote

\b     Backspace

\”      Double quote

\n      New line

These were only some of the JavaScript tips you can learn.

Get the entire PDF Cheatsheet containing ALL Javascript Basics.

Leave a Reply

Your email address will not be published. Required fields are marked *