Javascript |
Python |
Declaration using the var, let, or const keywords |
Declaration Created simply by assigning a value. No explicit declaration is required. |
Dynamically typed The type of a variable can change during runtime. |
Dynamically typed Allow variables to hold values of different types throughout their lifetime. |
Scoping Variables have function-level scope, meaning they are accessible within the function they are defined in. Variables declared with var are also hoisted, allowing them to be accessed before their actual declaration. |
Scoping Variables have block-level scope, meaning they are accessible within the block they are defined in. Python does not have variable hoisting. |
Variables in JavaScript typically follow camelCase naming convention (e.g., myVariable, firstName, totalAmount). |
Variables in Python typically follow snake_case naming convention (e.g., my_variable, first_name, total_amount). |
Variables can be declared without an initial value, and they will have the value undefined until assigned a value. variables do not have default values. |
Variables need to be assigned an initial value when they are created. Otherwise, a NameError will occur. variables have default values of None for non-primitive data types, and 0 for primitive data types. |
Variables declared outside of any function or block have global scope and can be accessed from anywhere in the code. |
Variables declared outside of any function or block have global scope, but accessing them from within a function requires the global keyword. |
The null and undefined values are different. null indicates that a variable has no value, while undefined indicates that a variable has not yet been defined. |
There is only one value for "no value", which is None |
JavaScript has a dynamic type system, which means that the type of a variable can change at runtime. |
Python has a static type system, which means that the type of a variable is known at compile time. |
variables can be assigned values using the equal sign (=) |
variables can be assigned values using the equals sign (=) or the colon (:) |
variables are mutable by default. This means that their values can be changed after they are assigned. |
variables are immutable by default. This means that their values cannot be changed after they are assigned. |
two variables are equal if they have the same value, regardless of their type |
two variables are equal if they have the same type and the same value. |
primitive data types: undefined, Boolean, String, Number, BigInt, Symbol, and null |
primitive data types: int, float, bool, and str |
type coercion is automatic. This means that if you try to perform an operation on two values of different types, the values will be automatically converted to the same type before the operation is performed. |
type coercion is not automatic. You must explicitly convert values to the desired type before performing an operation on them. |
Created By
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
Related Cheat Sheets