GithubHelp home page GithubHelp logo

js-cheatsheet's Introduction

Javascript Cheatsheet

Primitives (true/false), Variables, Data Structures, (Arrays, Objects (Brackets, Dot)), HOF, Flow Control (conditionals), Loops (for, while, for in), operators (math, logical, comparison), functions (parameters vs objects), scope, hoisting, callbacks, string concatenation, computer science (bigO), import/export functions, methods vs functions

Data Types

Primitives

A primitive is data that's immutable. In other words, data that can't be changed. Building blocks, Legos!

  1. Boolean - true or false
  2. Number - integers of floats
  3. String - text
  4. Undefined - value has not been defined
  5. Null - intentional absence of an object value (intentionally valueless)
  6. Symbol - (ES6)

Variables

Container to store a piece of data (values). Shortcut for storing data.

  1. Declare - using var
  2. Naming - can't start with a number, can't have spaces, avoid symbols except _, $, should be descriptive, use camelCase

Data Structures

  1. Arrays - container for primitives (and other data structures), accessed via index, maintain order
  2. Objects - key/value oarts, accessed via bracket or dot notation, not ordered

Programming Paradigms

Procedural vs Functional

  1. Procedural - Javascript renders commands in order (set of instructions)
  2. Functional - break apart code/problem logically, generally separate state from behavior

Flow Control

Decides which things run based on specific conditions or loops

  1. if else
  2. if
  3. else if
  4. else
  5. Can be nested

Loops

Runs a piece of code for a certain amount of iterations

  1. Infinite Loop - loop that runs forever, you can run out of memory
  2. For
  3. While
  4. For in
  5. For of
  6. Do While

scope

Range in which a varible can be accessed

  1. Local and Global (functional/lexical)
  2. Global - accessible everywhere; local accessible only when the function is invoked
function foo()
  {
    var test = 'some string';
    function bar()
    {
      console.log(test);
    }
  }

Hoisting

The process by which the computer moves all variable declarations to the top of the applicable scope, so that it never encounters a variable it is unaware of. It's important to note that it does not move the variable assignment to the top of the page.

var foo = bar;

moves declarations var foo; BUT NOT assignment var foo = bar;

Higher Order Functions

function can take functions; the function thats passed into the higher order function is the callback

async - different code can run at different times

what happens is one function is dependent on another functions output

function testing()
{
  return ing
}

function test()
{
  return 'test' + arg;
}

var x =testing()
test(x)

String Concatenation

used to join 2 or more strings

'test' + 'ing';

'test'.concat('ing')

you can also use +=

Computer Science

bigO Notation

Big-O notation is how developers discuss the complexity of an algorithm as a way to understand how fast a program will run given it's input. Big-O notation deals with the worst case scenario for the algorithm. In other words, if the program may run quickly, but there is a chance it could take a long time given some input, then the Big-O runtime will deal with the longer case.

  1. o(n) linear, direclty realted to input size
  2. o(1) - constant time, bound by a constant, regardless of input size runtime remains the same
  3. o(n^2) - quadratic time, a nested loops
  4. A "flogaritihm" of a postiive number (n) represent by (log(n)) is the number of digits it has
  5. factorial - complexity is worse then quadratic

Big O Cheatsheet

Operators

Math

  1. (+) Addition
  2. (-) Subtraction
  3. * Multiplication
  4. (/) Division
  5. (%) Modulus
  6. (++) Increment
  7. (--) Decrement

Assignment

  1. =
  2. +=
  3. -=
  4. *=
  5. /=
  6. %=

Comparison Operators

  1. == equal to
  2. === equal value and equal type
  3. != not equal
  4. !== not equal value or not equal type
  5. (>) greater than
  6. (<) less than
  7. (>=) greater than or equal to
  8. (<=) less than or equal to
  9. (?) ternary operator

Logical Operators

  1. (&&) both statements are true
  2. (||) either statements are true

Type Operators

  1. (typeof) Returns the type of a variable
  2. (instanceof) Returns true if an object is an instance of an object type

Functions

a reusable code block that does one specific thing

  1. methods vs functions - method is a function that is contained within an object
  2. functions are first class citizens and can be used as arguments
  3. can have optional
  4. functions always return somethingl if not explicitly set, then it returns undefined

Parameter

A Parameter is a variable in the signature of a function declaration or definition:

function (parameter) {

}

Argument

An Argument is the value that gets passed to the function when calling it:

function(argument);

Creating Functions

function greet() {
  console.log("Hello, World!");
}

Invoking Functions

Type the name of the function

greet

js-cheatsheet's People

Contributors

tommygaessler avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.