ES6 Notes

I HOPE this code is ES6 it IS JavaScript 🙂

GOOD STUFF:
Python VS ES6 syntax comparison

/* BUMMERS: 
  - as of Nov 2, 2017 import statements are NOT in Node.js LTS 
  - ES6 postponed Array comprehensions (likePython). 
        (https://stackoverflow.com/a/35637068/601770)
  - typeof object name discovery: https://stackoverflow.com/q/332422/601770
*/

/* read to string one liner */
var mystr= fs.readFileSync("./mytextfile.txt").toString('utf-8')

/* for-of */
let myIterable = [10, 20, 30]

for (let value of myIterable ) {
  value += 1
  console.log(value)
}
// 11
// 21
// 31

/* timestamp */
let ts = (new Date().toISOString()).replace(/:/g, '.').replace('T', '__').slice(0, -5)
// 2017-11-13__18.33.16


/* string format %s   */
const util = require('util')
util.format('Timestamp: %s', '2017-11-13_18.26.52')
// 2017-11-13_18.26.52

/* slice NOT same as Python */
 +---+---+---+---+---+
 | H | e | l | p | A |
 +---+---+---+---+---+
 0   1   2   3   4   5
-5  -4  -3  -2  -1

> s.slice(null)
'HelpA'
> s.slice(0)
'HelpA'
> s.slice(-1)
'A'
> s.slice(-5)
'HelpA'
> s.slice(null,null)
''
> s.slice(null, 5)
'HelpA'
> s.slice(null, 4)
'Help'
> s.slice(0, 4)
'Help'
> s.slice(0, -2)
'Hel'







Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s