Pass in value with Object literals in JavaScript

Description

The following code shows how to pass in value with Object literals.

Example


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function displayInfo(args) {<!--  ww  w  . j  a v a  2s .  c om-->
if (typeof args.name == "string"){
document.writeln("Name: " + args.name);
}
if (typeof args.pageSize == "number") {
document.writeln("PageSize: " + args.age);
}
document.writeln(output);
}
displayInfo({
name: "JavaScript",
pageSize: 9
});

displayInfo({
name: "HTML"
});

</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Pass in value with Object literals in JavaScript