I hereby propose this form of let usage as the next best option, since the clearly better let (foo = 42) { ... } let-block-statement syntax is dead and not coming to ES6:
/*let*/ { let foo = 42;
// your code that uses `foo`
}| /** | |
| * Helper functions | |
| */ | |
| // Map array elements with functions | |
| var mapForEach = function(arr, fn) { | |
| var newArr = []; | |
| for (var i=0; i< arr.length; i++) { | |
| newArr.push( | |
| fn(arr[i]) // pass array item element to the function |
| function createVehicle(vehicleType){ | |
| return function(brand) { | |
| if (vehicleType === 'Car') { | |
| console.log('Achieve New Car! Brand:' + brand); | |
| } | |
| if (vehicleType === 'Truck') { |
| //Closure example | |
| function greet(whatToSay) { | |
| // get value back when invoke function | |
| // get back function | |
| return function(name) { | |
| console.log(whatToSay + ' ' + name); | |
| }; | |
| } |
I hereby propose this form of let usage as the next best option, since the clearly better let (foo = 42) { ... } let-block-statement syntax is dead and not coming to ES6:
/*let*/ { let foo = 42;
// your code that uses `foo`
}Short link: www.bit.ly/js-courses-list (NB: if you click it from this document recursion may occur :) )
| name or author | url | duration, week/month | price, rub |
|---|---|---|---|
| HTML Academy | https://htmlacademy.ru/intensive/javascript | 5w | 19 500 |
| Ilya Kantor | 2m | 26000 |