Skip to content

Instantly share code, notes, and snippets.

@VinayakHegde
Created January 8, 2024 23:57
Show Gist options
  • Save VinayakHegde/df2f569d17259d0282a08dc76f94514c to your computer and use it in GitHub Desktop.
Save VinayakHegde/df2f569d17259d0282a08dc76f94514c to your computer and use it in GitHub Desktop.
Aspect JavaScript Python
Primary Numeric Data Type number int and float
String Data Type string str
Boolean Data Type boolean bool
Array/List Data Type array list
Object/Dictionary Data Type object dict
Set Data Type Set set
Tuple Data Type Not directly supported tuple
Function Declaration function functionName() { /* code */ } def function_name():
Arrow Functions (Lambda) (param) => expression lambda param: expression
Object Initialization const obj = { key: value }; obj = {'key': value}
Variable Declaration let variableName = value; variable_name = value
Conditional Statements if (condition) { /* code */ } else { /* code */ } if condition: # code else: # code
Switch/Case Statement switch (expression) { case value: /* code */ break; default: /* code */ } match expression: case value: # code break case _default: # code
For Loop for (let i = 0; i < length; i++) { /* code */ } for i in range(length): # code
For...of Loop for (const element of array) { /* code */ } for element in array: # code
While Loop while (condition) { /* code */ } while condition: # code
Do...While Loop do { /* code */ } while (condition); while True: # code if not condition: break
Try/Catch Statement try { /* code */ } catch (error) { /* code */ } try: # code except Exception as error: # code
Throwing Exceptions throw new Error('message'); raise Exception('message')
Comments // Single-line comment # Single-line comment
Multi-line Comments /* Multi-line comment */ ''' Multi-line comment '''
Object Destructuring const { key1, key2 } = obj; key1, key2 = obj['key1'], obj['key2']
Array Destructuring const [element1, element2] = array; element1, element2 = array[0], array[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment