Created
October 25, 2021 02:50
-
-
Save jonrandy/2a31fc1dea4406ae39e94fa133fb870d to your computer and use it in GitHub Desktop.
JS Golfing Tips
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var n = 53.73; | |
var rounded = n|0; //53 | |
x|0 //Round x down | |
func`arg` //Call function with one string argument | |
getContext`2d`; // ^ | |
`rgb(${r}, ${g}, ${b})` //Template literals | |
C //together with <canvas id=C> instead of document.getElementById("C"); | |
1e3 //Shorter than 1000 | |
1e-3 //Shorter than 0.001 | |
setInterval(`console.log("something")`, 100) //Instead of function() { ... } | |
(a,b)=>a+b //Arrow function | |
_=>{} //Instead of ()=>{} | |
a=5 //Remove var (be careful with global vars) | |
innerWidth //Remove window (Instead of window.innerWidth) | |
99 //Sometimes 99 works instead of 100 or 9 istead of 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment