-1

I was reading about Javascript and I came across javascript object notation and I was quite fascinated.

For example,

var myObject = {
    name: "Peter Foti",
    'course': 'JavaScript',
    grade: 'A', 
    level: 3
};

Why couldn't I do a JSON Object instead of using an object? When should we use Javascript objects as opposed to sending JSON Object?

Kinda confused here.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
TechnoCorner
  • 4,879
  • 10
  • 43
  • 81
  • 2
    Your question makes very little sense: JSON is a serialisation standard (language independent) and JS object notation is just the way you define objects in JS. They are different things. – zerkms May 07 '16 at 08:37
  • JSON is a data interchange format equivalent in syntax to JavaScript-the-language's object notation. With your above statement you create an object named `myObject` used in a running program. If you put the object's definition, just the part between and including the brackets `{ ... }`, into a file or transmit it as a message over the net, that's known to be in the JSON format. – miraculixx May 07 '16 at 08:39
  • `JSON` is a string – guest271314 May 07 '16 at 08:39
  • 3
    JSON never should've been called "JSON", because it's been causing confusion with JS *code* ever since. (Not sure what else to call it - "SOS" for "simple object serialisation"?) – nnnnnn May 07 '16 at 08:44
  • You should read: [There's no such thing as a "JSON Object"](http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/). – Felix Kling May 07 '16 at 16:07

1 Answers1

1

You should use JSON (like XML or other structured language) in order to provide informations to other languages/system while Javascript object are type var live in javascript environment and therefore cannot be shared.

Jean-Luc Barat
  • 1,147
  • 10
  • 18