Object Literals - Javascript Language Basics

Javascript examples for Language Basics:Introduction

Introduction

You can define an object and its properties in one step using the object literal format.

Demo Code

ResultView the demo in separate window

<!DOCTYPE HTML>
<html>
    <head>
        <title>Example</title>
    </head>
    <body>
        <script type="text/javascript">
            var myData = {//from   w ww  .  ja v a 2  s.c  om
                name: "java2s.com",
                topic: "CSS"
            };

            document.writeln("Hello " + myData.name + ". ");
            document.writeln("Today is " + myData.topic + ".");
        </script>
    </body>
</html>

Related Tutorials