Thursday, 21 January 2016

Creating JavaScript Objects

Objects are just data, with properties and methods.
Almost everything in JavaScript can be an Object: Strings, Functions, Arrays.

person=new Object();
person.firstname="John";
person.lastname="Doe";
person.age=50;
person.eyecolor="blue";

Example:

<!DOCTYPE html>
<html>
<body>
<script>
var person=new Object();
person.firstname="John";
person.lastname="Doe";
person.age=50;
person.eyecolor="blue";
document.write(person.firstname + " is " + person.age + " years old.");
</script>
</body>

</html> 

0 comments:

Post a Comment