To show an alert message in JavaScript, you can use the alert()
function. The alert()
function displays an alert box with a specified message and an OK button. Here is an example:
index.tsx24 chars2 lines
When you run this code, it will display an alert box with the message "Hello, World!".
You can also include variables or expressions in the message by using concatenation or template literals:
index.tsx45 chars3 lines
or
index.tsx43 chars3 lines
Both of these examples will display an alert box with the message "Hello, Alice" or "Hello, Bob", depending on the value of name
.
Keep in mind that alerts can be annoying for users if overused or misused. It's often better to use other methods of displaying information, such as the DOM or console output, depending on the context of your application.
gistlibby LogSnag