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
| //ES5 | |
| var list = [1, 2, 3]; | |
| var a = list[0], | |
| b = list[2]; | |
| console.log(a, b); | |
| //ES6 | |
| var [a, , b] = list; | |
| console.log(a, b); |
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
| //ES5 | |
| obj = { | |
| fn1: function (a, b) { | |
| return ''; | |
| }, | |
| fn2: function (x, y) { | |
| return ''; | |
| }, | |
| }; |
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
| //ES5 | |
| var indexFn = function () { | |
| return 1; | |
| }; | |
| var objES5 = { | |
| name: 'Can', | |
| }; | |
| objES5['Columnn' + indexFn()] = 42; | |
| console.log(objES5); | |
| //output |
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
| //ES5 | |
| var x = 0, y = 0; | |
| obj = { x:x, y:y }; | |
| console.log(obj.x); | |
| //ES6 | |
| var x = 0, y = 0; | |
| obj = { x, y }; | |
| console.log(obj.x); |
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
| //ES5 | |
| var a = 3; | |
| var b = 5; | |
| var flag = true; | |
| var flagResult = flag === true ? ',\nBingoo' : ''; | |
| var result1 = a + ' * ' + b + ' = ' + a * b + "'dir" + flagResult; | |
| console.log(result1); | |
| //output | |
| // 3 * 5 = 15'dir, |
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
| //ES5 | |
| var user = { name: 'Ali' }; | |
| var product = { brand: 'apple', unitprice: 100 }; | |
| var message = | |
| 'Hoş geldin ' + | |
| user.name + | |
| ',\n' + | |
| product.brand + | |
| ' markalı ürünümüzün fiyatı' + | |
| product.unitprice + |
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
| -- how to use: | |
| -- redis-cli EVAL "$(cat redis-idle-clean.lua)" 2 key_name 86400 | |
| local keyTemplate = KEYS[1] | |
| local keyMinIdleTime = tonumber(KEYS[2]) | |
| local function getUsedMemory() | |
| local info = redis.call('info') |
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
| ///// Array ///// | |
| //ES5 | |
| var nameArrayEs5 = ["ramazan","duygu"]; | |
| var newArrayEs5 = ["enis","kübra"].concat(nameArrayEs5); | |
| console.log(newArrayEs5); | |
| //output | |
| [ 'enis', 'kübra', 'ramazan', 'duygu' ] | |
| //ES6-spread | |
| var nameArray = ["ramazan","duygu"]; |
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
| //ES5 | |
| function addNumbers(first, second) { | |
| var numbers = Array.prototype.slice.call(arguments, 2); | |
| return numbers.reduce((sum, number) => { | |
| return sum + number; | |
| }, first + second); | |
| } | |
| console.log(addNumbers(1, 2, 3, 4, 5)); | |
| //output |
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
| //ES5 | |
| function add (x, y, z) { | |
| if (y === undefined) | |
| y = 7; | |
| if (z === undefined) | |
| z = 42; | |
| return x + y + z; | |
| }; | |
| console.log(add1(1) === 50); | |
| //ES6 |