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
////////////////////////////////////////////// | |
// 1. variable declaration | |
////////////////////////////////////////////// | |
// Longhand | |
var var1; | |
var var2 = 'Yes'; | |
var var3 = 3; | |
// Shorthand | |
var var1, | |
var2 = 'Yes', | |
var3 = 3; | |
// Shortenerhand :D | |
var var1, var2 = 'Yes', var3 = 3; | |
////////////////////////////////////////////// | |
// 2. if true ... else | |
////////////////////////////////////////////// | |
// Longhand | |
var many; | |
if (x > 10) { | |
many = 'Yes'; | |
} | |
else { | |
many = 'No'; | |
} | |
// Shorthand | |
var many = (x > 10) ? 'Yes' : 'No'; | |
////////////////////////////////////////////// | |
// 3. Check !null, !undefined, !empty('') | |
////////////////////////////////////////////// | |
// Longhand | |
if (var1 !== null || var1 !== undefined || var1 !== '') { | |
// something | |
} | |
// Shorthand | |
if (var1) { | |
// something | |
} | |
////////////////////////////////////////////// | |
// 4. Assign if !null, !undefined, !empty('') | |
////////////////////////////////////////////// | |
// Longhand | |
if (var1 !== null || var1 !== undefined || var1 !== '') { | |
var var2 = var1; | |
} | |
// Shorthand | |
var var2 = var1 || ''; | |
////////////////////////////////////////////// | |
// 5. assignment operators | |
////////////////////////////////////////////// | |
// Longhand | |
x = x + y; | |
x = x - y; | |
x = x * y; | |
x = x / y; | |
x = x % y; | |
// Shorthand | |
x += y; | |
x -= y; | |
x *= y; | |
x /= y; | |
x %= y; |
Keine Kommentare:
Kommentar veröffentlichen