Objects in Dynamically Typed Languages like JavaScript

CS 301: Assembly Language Programming Lecture, Dr. Lawlor

First, let's address the the biggest misconception about JavaScript:
The cool part about JavaScript is you can embed interactive stuff in web pages, like this:
Code Demo Page on jsbin.com

The biggest difference between JavaScript and C++ is JavaScript uses dynamic typing--you declare any kind of variable with "var".  At runtime, you can ask what a variable's type is using "typeof", which will return one of these:

JavaScript typeof
C++ type (roughly)
var x=3;
int, float, double
var x="bob";
std::string, char *
var x=false;
var x=function() {...};
any function, method
var x={"y":3};
any class, struct, or map!
var x=[2,3,5];
std::vector, array
var x;

Javascript doesn't even force you to declare variables--any newly encountered variable is treated as having the value "undefined".  This can be annoying, because when you typo a variable name, you don't get a compile error, only a crash at runtime ("Uncaught TypeError: Cannot call method of undefined").

Javascript objects are also very surprisingly flexible--you can add new methods and fields to any object at any time!
Code Demo Page on jsbin.com

That JSON.stringify converts an object to a string representation in JavaScript Object Notation, an increasingly common data format. 

Internally, a JSON object is stored in a dynamically allocated data structure similar to a std::map<std::string, value *> (for example, see this C++ implementation of JSON objects).   Because dynamic allocation is expensive, high performance libraries like the 3D rendering package three.js have an incentive to re-use objects.