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
| function balancedParens(string){ | |
| return !string.split("").reduce(function(previous, char){ | |
| if(previous < 0) { return previous; } | |
| if(char === "(") { return ++previous; } | |
| if(char === ")") { return --previous; } | |
| return previous; | |
| }, 0); | |
| } | |
| balancedParens("(()()())()"); | |
| //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
| const PI = 3.141593; | |
| console.log(PI > 3); | |
| //output | |
| true | |
| PI = 34; | |
| console.log(PI); | |
| //output TypeError |
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
| Object.defineProperty(typeof global === "object" ? global : window, "e", { | |
| value: 2.7182, | |
| enumerable: true, | |
| writable: false, | |
| configurable: false | |
| }) | |
| console.log(e > 3); | |
| //output | |
| false |
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
| //var function scoped | |
| //let block scoped | |
| function test1() { | |
| if (true) { | |
| var dummy1 = 'var belirtecinden'; | |
| let dummy2 = 'let belirtecinden'; | |
| console.log(dummy1); | |
| //output => var belirtecinden | |
| console.log(dummy2); |
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
| ///// block-scoped function ES5 | |
| (function(){ | |
| function privateFunc(){ | |
| console.log("Bu scope dışından erişelemez"); | |
| (function(){ | |
| console.log("Bu scope dışından erişilemez, privateFunc'tan da erişilemez"); | |
| })(); | |
| } | |
| privateFunc(); | |
| })(); |
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 that, this ataması yapılmalı ya da bind edilmeli | |
| var obj = { | |
| nums: [1, 2, 3, 4, 5, 6, 10], | |
| fives: [], | |
| hop: function() { | |
| var that = this; | |
| this.nums.forEach(function(v) { | |
| if(v % 5 ===0) | |
| that.fives.push(v); | |
| }); |
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
| var add = (a,b) => { | |
| return a + b; | |
| } | |
| console.log(add(2,3)); | |
| //output | |
| 5 |
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
| var add = (a,b) => a + b; | |
| console.log(add(2,3)); | |
| //output | |
| 5 |
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
| const numbers = [1,2,3,4]; | |
| var doubledArray = numbers.map(function(number){ | |
| return 2 * number; | |
| }); | |
| console.log(doubledArray); | |
| //Yukarıdaki fonksiyon ile aynı işi yapan daha yalın tanımlama | |
| var doubledArray = numbers.map(number => 2 * number); | |
| console.log(doubledArray); | |
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 |