To display JavaScript variable value in an alert box, try to run the following code −
Example
<html>
<head>
<script>
function display() {
var a = "Simple";
var b = "Learning";
alert(a +" Easy "+ b);
}
</script>
</head>
<body>
<input type="button" value="Click me!" onClick="display();">
</body>
</html>