How different are the semantics between Python and JavaScript?
- Classical inheritance in Python, Prototypal inheritance in ECMAScript
- ECMAScript is a braces and semicolons language while Python is white-space and indent/block based
- No
var
keyword in Python, implicit globals in ECMAScript, both are lexically scoped - Closures in Python 2.5 and lower ( re: Alex Martelli's comment ) are somewhat "limited" because the bindings are read-only, you can't access private variables like you could in ECMAScript
- There's no
undefined
in Python, exceptions are thrown - Immutable list arrays in Python ( tuples )
- No
switch
statement in Python but instead you're encouraged to use a dictionary in that manner, sometimes its convenient assigning properties to lambdas and executing them - ECMAScript 3 does not have a
yield
statement, norlet
expressions/statements, norarray comprehension
s - however these are included in Mozilla's JS which is non-standard raise
vsthrow
,except
vscatch
( Python, JS )- Native Unicode strings in ECMAScript
- keyword operators such as
and
,is
, andnot
are used in Python - Python doesn't support counters such as
i++
- Python's for loop is "smart" so you don't need to use a counter for enumerating through lists, nor do you run into prototypal properties inherited from
Object.prototype
- You don't have to use the
new
operator in Python to create objects - Python is duck-typed
I stole a good bit of info from http://hg.toolness.com/python-for-js-programmers/raw-file/tip/PythonForJsProgrammers.html
Typing: Javascript and Python are both dynamically typed, whereas javascript is weakly, python strongly typed.
In python, "self" is explicitly passed to a member function, and is not a special keyword or anything.In javascript, "this" is dynamically scoped. you can fiddle with the scope of a member function by calling apply() on it.