0

Will anyone please explain the difference between object and object literals in JavaScript?

So far I learned by searching google is given bellow:

1) Object is a collection of name-value pairs like: address:"my address".

2) Object Literals are a sequence of name-value pairs separated by commas and surrounded by curly braces. For example: {address: "my address", roll: 0001}

But its still not making sense to me. I can't find out the basic differences between these two. Actually, I'm confused with the 'collection of name-value pair' and 'sequence of name-value pairs'.

M H Rahman
  • 49
  • 8
  • 1
    An object literal is just the name for the syntax to define an object in-line. It's also called [object initializer notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer). – 4castle Nov 24 '16 at 19:53

1 Answers1

1

An object literal is simply an object that is literally defined, as in

var object_literal = {
    key1 : "value",
    key2 : "value2",
}

However there are many types of objects in javascript, for instance

var obj1 = new Date();    // object
var obj2 = function() {}; // object
var obj3 = new RegExp();  // object

and many, many more, but these are not literal objects

adeneo
  • 312,895
  • 29
  • 395
  • 388