1. REPL (Read Eval Print Loop)
- Python:
- JavaScript:
You’ll get it with the installation of python and call different python versions depending on the installation.
Javascript doesn’t have inbuilt REPL as most of the time developers run in a browser, but you can use REPL by installing node.js.
2. Mutability
- Python:
- JavaScript:
Python has mutable and immutable data types like set (mutable) and list (immutable).
Javascript has no concept of mutable and immutable.
3. Strings
- Python:
- JavaScript:
In python source code is ASCII by default unless you specify any encoding format.
Javascript should be encoded as UTF-16 and no built-in support for manipulating raw bytes.
4. Numbers
- Python:
- JavaScript:
In python, you’ve different numeric types like integer (int), float, fixed-point decimal, etc.
Javascript has only floating point numbers only.
5. Hash tables
- Python:
- JavaScript:
Python has built-in hash tables, called dictionaries, sets, etc, which can be used in hashing with keys and values.
Javascript has no built-in hash table support.
6. Inheritance
Python:
Python uses class-based inheritance model.
The example above shows you a class definition and init function is a constructor.
JavaScript:
Javascript uses prototype based inheritance model.
7. Code Blocks
- Python: Python uses indentation.
- JavaScript: Javascript uses curly brackets.
8. Function Arguments
- Python: Python will raise an exception if a function is called with incorrect parameters and accepts some additional parameter passing syntax.
- JavaScript: Javascript doesn’t care whether functions called with exact parameters are not as by default any missing parameter gets a value as “undefined” and any extra arguments end as special arguments.
9. Data types
- Python: Python has two similar data types list and tuple. Python list and javascript array are quite similar.
- JavaScript: Javascript has inbuilt array type.
10. Properties and Attributes
- Python: Python allows to define an attribute using descriptor protocol where you can use a getter, setter functions.
- JavaScript Javascript objects have properties which can be composed of underlying attributes and it let’s you define a property.
11. Modules
- Python: Python calls itself as a batteries included language as it comes with a wide range of modules.
- JavaScript: Javascript comes with very few modules like date, math, regexp, JSON and it has the functionality available through host environment like a web browser or other environment.
Join my telegram channel
Top comments (4)
Python has mutable and immutable data types like set (mutable) and list (immutable).
Both set and list are mutable in Python afaik. Tuples aren't.
Javascript has no concept of mutable and immutable.
That is not quite true. Conceptually, immutability exists in js as it does in most languages I believe.
Some methods are mutative while others aren't (push vs concat for instance).
You can also use
Object.freeze
to prevent an object from being mutated.Javascript has no built-in hash table support.
JavaScript has objects which can pretty much be used the same way as maps, but it also has the
Map
andSet
built-in.Thank you for your comment and correcting me!
Thanks for sharing informative article. Both Python and JavaScript have consistently remained at the top of the most popular programming languages. Both are object-oriented programming languages, their scopes are different. Python and JS have a lot in common but with some significant differences. JavaScript is a scripting language used to create and control dynamic website content and Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Python beats JavaScript at data science and user-friendliness, JavaScript surpasses Python in frontend development and performance. compersion is better to understand which is better, Found one blog check out here bit.ly/380n5LK
Great overview.
I was a little surprised that integers are not part of JavaScript, but then I checked that
typeof 7
returns "number". The same as any other type of number.