Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Set a Default Value for a Function Parameter</title> </head> <body> <script> // Defining a function function sayHi(name = 'There') { document.write('<p>Hi, ' + name + '</p>'); } sayHi(); // Prints: Hi, There sayHi('Peter'); // Prints: Hi, Peter </script> </body> </html>