create function in python in javascript

Function in Python

To create a function in Python, we can use the def keyword followed by the function name and parameters enclosed in parenthesis. The code block inside the function is indented.

main.py
def greet(name):
    print(f"Hello, {name}!")

greet("John")   # Output: Hello, John!
86 chars
5 lines

Function in JavaScript

In JavaScript, we can declare a function using the function keyword followed by the function name and parameters enclosed in parenthesis. The code block inside the function is enclosed in curly braces.

index.tsx
function greet(name) {
    console.log(`Hello, ${name}!`);
}

greet("John");   // Output: Hello, John!
103 chars
6 lines

We can also create an arrow function in JavaScript using the => operator.

index.tsx
const greet = (name) => {
    console.log(`Hello, ${name}!`);
}

greet("John");   // Output: Hello, John!
106 chars
6 lines

I hope this helps you!

gistlibby LogSnag