Java Reference
In-Depth Information
function hello(name) {
var name = name || "JavaScript";
return "Hello " + name;
Instead, we can save the line of code at the beginning of the function and set the default
value when the parameter is defined by assigning a value inside the parentheses:
function hello(name = "JavaScript") {
return "Hello " + name;
Now if no argument is provided, the default value will be used:
<< "Hello Ninja"
<< "Hello JavaScript"
Harmony will introduce a new notation for using promises . The increase in the use of asyn-
chronous programming in JavaScript has meant that more and more callbacks are used.
This can result in messy and confusing “spaghetti code” when more than one callback is
used in the same function. A promise is used to call a piece of asynchronous code without
having to use multiple callbacks. Promises don't do anything that can't already be achieved
using callbacks, but they aim to simplify the process and avoid the convoluted code that
can result from using multiple callbacks.
A promise deals with these phases of an operation's execution:
• pending―the operation hasn't failed or been fulfilled
• fulfilled―the operation was successful
• failed―the operation didn't work
Search WWH ::

Custom Search