Skip to content

Instantly share code, notes, and snippets.

@benjiqq
Last active December 24, 2015 12:49
Show Gist options
  • Save benjiqq/6800298 to your computer and use it in GitHub Desktop.
Save benjiqq/6800298 to your computer and use it in GitHub Desktop.
Javascript cheat sheet
//Math
Math.round(.6)
Math.random( )
Math.PI
Math.sin(0)
//Strings
var s = "hello world"
s.charAt(0)
s.charAt(s.length-2)
s.substring(1,4)
s.slice(-3)
s.lastIndexof("l")
s.replace("h","H")
s.toUpperCase()
//
var n = 18
n.toString(2) //convert by base
//parse
parseInt("2 M") //=2
//var decleration
var i = 1, j = 2, k = 3
for (var i = 0; i < 10; i++) console.log(i)
var matrix = [[1,2,3],[5,6,7],[-1,-5,-9]]
//objects
var p = { x : 2, y: 1}
var q = { }
q.xx = 123
q["xx"] === 123
"xx" in q
Math.max(1,2)
//typeof
typeof q["xx"]
typeof typeof q["xx"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment