This repository was archived by the owner on Dec 12, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathJavaScript Cheat Sheet.txt
More file actions
72 lines (37 loc) · 1.26 KB
/
JavaScript Cheat Sheet.txt
File metadata and controls
72 lines (37 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Smart rounding
Another use of binary operators is rounding. Because they treat numbers as integers, all of them cut off the decimal part.
~~12.34 // 12
-------------------------------------------------------------------
Smart division by power of 2
The right shift a >> b operator is actually same as a/(2^b).
----------------------------if---------------------------------------
Conditions can be grouped in brackets and negated by NOT:
var x = 15
if ( !(x<10 || x>20) ) {
alert('The number is *inside* 10..20')
}
------------------------switch---------------------------------------
var x = 2
switch(x) {
case 1:
alert('never executes')
break
case 2:
alert('x === 2') // <-- start
break // stop!
case 3:
alert('x === 3')
break
}
---------------------------Special characters-------------------------
Here is a list of special characters and sequences:
Character Description
\b Backspace
\f Form feed
\n New line
\r Carriage return
\t Tab
\uNNNN The Unicode character which code is given by the four hexadecimal digits NNNN.
For example, \u00A9 is the Unicode sequence for the copyright symbol.
Note that strings in JavaScript are Unicode internally.
The newline symbol is by far the most popular: