Example of Javascript code
// JavaScript code to greet the user
// Prompt the user for their name
var userName = prompt("What is your name?");
// Check if the user entered a name
if (userName !== null && userName !== "") {
// Display a personalized greeting
alert("Hello, " + userName + "! Welcome to the world of JavaScript.");
} else {
// Handle the case where the user didn't enter a name
alert("Hello, anonymous! Welcome to the world of JavaScript.");
}
Output:
What is your name?
Hello, Geek! welcome to the world of javascript
.js Program Format
A .js program format refers to the structure and organization of JavaScript code files. It typically includes script tags for inline code or external file references, functions, variable declarations, and statements. Proper formatting enhances readability, maintainability, and collaboration in software development projects.