Created
April 6, 2017 12:36
-
-
Save kalisjoshua/7b265b7da994afea852b030964a9ee10 to your computer and use it in GitHub Desktop.
Collection of interesting JavaScript syntax.
This file contains hidden or 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. | |
// replace instances with different replacement strings | |
const qwerty = 'qw#rt#'.replace(/#/g, [].shift.bind(['e', 'y'])); | |
// 2. | |
// make Array.slice available as a function instead of a method | |
const slice = Function.prototype.call.bind(Array.prototype.slice); | |
// 3. | |
// ASI (failure) working in conjunction with the comma operator | |
var name = { Goodbye: [1, 2, 3] } | |
// not an array; bracket notation addressing "Goodbye" property | |
// of the preceeding object because there is no semi-colon | |
[ 'Hello', 'Goodbye' ].forEach(function (value) { | |
// `name` is undefined because `forEach` returns nothing | |
console.log(`${value} ${name} <br />`) | |
}) | |
;(function () { | |
const q = { Goodbye: [1, 2, 3] }[ 'Hello', 'Goodbye' ] | |
console.log(typeof q, q) | |
}()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment