Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript ES6 Arrow Functions Variations</title> </head> <body> <script> // Single parameter, single statement var greet = name => document.write("Hi " + name + "!"); greet("Peter"); // Hi Peter! document.write("<br>"); // Multiple arguments, single statement var multiply = (x, y) => x * y; document.write(multiply(2, 3)); // 6 document.write("<br>"); // Single parameter, multiple statements var test = age => { if(age > 18) { document.write("Adult"); } else { document.write("Teenager"); } } test(21); // Adult document.write("<br>"); // Multiple parameters, multiple statements var divide = (x, y) => { if(y != 0) { return x / y; } } document.write(divide(10, 2)); // 5 document.write("<br>"); // No parameter, single statement var hello = () => document.write('Hello World!'); hello(); // Hello World! </script> </body> </html>