How different are the semantics between Python and JavaScript?

后端 未结 6 1195
無奈伤痛
無奈伤痛 2021-01-30 09:36

Both these languages seem extremely similar to me. Although Python supports actual classes instead of being prototype-based, in Python classes are not all that different from f

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-30 09:58

    I'll add a few I haven't seen mentioned yet:

    • JavaScript supports object-literal notation. Python doesn't exactly work the same way, but Python dictionaries are similar to JavaScript associative arrays.
    • JavaScript objects/arrays support that cool feature where you don't need to quote (single-word) strings when creating new objects:

      var foo = { bar: "baz" };

    • Accessing associative array keys in JavaScript can be done using dot notation, in addition to brace notation. That is, these are the same:

      foo.bar; //returns "baz"

      foo["bar"]; // returns "baz"

    • Python's anonymous function (lambda) syntax is not as flexible as JavaScript's anonymous functions.

    • Python has, like, a standard library and stuff. (And yes, I know about Rhino et al., but the libraries they give you are not standard. There's no standardized way to read a file in JavaScript... that I know of.)
    • You can run JavaScript in a browser. Python... not so much. ;)

提交回复
热议问题