Skip to content

cotrFuncSyntax

Outlines the syntax for functions

Aliases:

  • cotrFuncSyntax
  • functionSyntax
  • functionDocs

cpp

// C++ Function Syntax
// Basic function: returnType functionName(parameters) { ... }
// Function with arguments: returnType functionName(arg1Type arg1, arg2Type arg2, ...) { ... }
// C++ does not support named arguments in the same way as some other languages.

csharp

// C# Function Syntax
// Basic function: public returnType FunctionName(parameters) { ... }
// Function with arguments: public returnType FunctionName(argType argName, ...) { ... }
// Named parameters in method calls: FunctionName(argName: value, ...);

dart

// Dart Function Syntax
// Basic function: returnType functionName(parameters) { ... }
// Function with arguments: returnType functionName(arg1Type arg1, arg2Type arg2, ...) { ... }
// Function with named arguments: returnType functionName({arg1Type arg1, arg2Type arg2, ...}) { ... }

go

// Go Function Syntax
// Basic function: func FunctionName(parameters) returnType { ... }
// Function with arguments: func FunctionName(arg1 type1, arg2 type2, ...) returnType { ... }
// Note: Go does not support named arguments in function definitions.

haskell

-- Haskell Function Syntax:
-- Basic function:
-- functionName :: parameterTypes -> returnType
-- functionName parameters = expression
-- Function with arguments:
-- functionName arg1 arg2 ... = expression

java

// Java Function Syntax
// Basic function: public returnType functionName(parameters) { ... }
// Function with arguments: public returnType functionName(argType argName, ...) { ... }
// Note: Java does not support named arguments in function definitions.

javascript

// JavaScript Function Syntax
// Basic function: function functionName(parameters) { ... }
// Function with arguments: function functionName(arg1, arg2, ...) { ... }
// Function with named arguments (using object destructuring): function functionName({arg1, arg2, ...}) { ... }

javascriptreact

// JavaScript Function Syntax
// Basic function: function functionName(parameters) { ... }
// Function with arguments: function functionName(arg1, arg2, ...) { ... }
// Function with named arguments (using object destructuring): function functionName({arg1, arg2, ...}) { ... }

kotlin

// Kotlin Function Syntax
// Basic function: fun functionName(parameters): ReturnType { ... }
// Function with arguments: fun functionName(arg1: Type1, arg2: Type2, ...): ReturnType { ... }
// Function with named arguments and default values: fun functionName(arg1: Type1 = defaultValue1, arg2: Type2 = defaultValue2, ...): ReturnType { ... }

perl

# Perl Function Syntax
# Basic function:
# sub functionName {
# my parameters) = @_;
# # Your code here
# }
# Function with arguments:
# sub functionName {
# my arg1,arg2, ...) = @_;
# # Your code here
# }

php

// PHP Function Syntax
// Basic function: function functionName(parameters) { ... }
// Function with arguments: function functionNamearg1,arg2, ...) { ... }
// Note: PHP does not support named arguments in function definitions.

powershell

Terminal window
# PowerShell Function Syntax
# Basic function:
# function functionName {
# param (
# parameters
# )
# # Your code here
# }
# Function with arguments:
# function functionName {
# param (
# [Type]arg1,
# [Type]arg2,
# ...
# )
# # Your code here
# }

python

# Python Function Syntax
# Basic function: def function_name(parameters): ...
# Function with arguments: def function_name(arg1, arg2, ...): ...
# Function with named arguments: def function_name(*, arg1=value1, arg2=value2, ...): ...

ruby

# Ruby Function Syntax
# Basic function: def function_name(parameters) ... end
# Function with arguments: def function_name(arg1, arg2, ...) ... end
# Function with named arguments: def function_name(arg1: value1, arg2: value2, ...) ... end

rust

// Rust Function Syntax
// Basic function: fn function_name(parameters) -> return_type { ... }
// Function with arguments: fn function_name(arg1: type1, arg2: type2, ...) -> return_type { ... }
// Note: Rust does not support named arguments in function definitions.

scala

// Scala Function Syntax:
// Basic function:
// def functionName(parameters): ReturnType = { ... }
// Function with arguments:
// def functionName(arg1: Type1, arg2: Type2, ...): ReturnType = { ... }
// Function with named arguments and default values:
// def functionName(arg1: Type1 = defaultValue1, arg2: Type2 = defaultValue2, ...): ReturnType = { ... }

shellscript

Terminal window
# Bash Function Syntax:
function functionName {
// Your code here
}

swift

// Swift Function Syntax
// Basic function: func functionName(parameters) -> ReturnType { ... }
// Function with arguments: func functionName(arg1: Type1, arg2: Type2, ...) -> ReturnType { ... }
// Function with named arguments: func functionName(arg1Name arg1: Type1, arg2Name arg2: Type2, ...) -> ReturnType { ... }

typescript

// TypeScript Function Syntax
// Basic function: function functionName(parameters): ReturnType { ... }
// Function with arguments: function functionName(arg1: Type1, arg2: Type2, ...): ReturnType { ... }
// Function with named arguments: function functionName({arg1, arg2, ...}: {arg1: Type1, arg2: Type2, ...}): ReturnType { ... }

typescriptreact

// TypeScript Function Syntax
// Basic function: function functionName(parameters): ReturnType { ... }
// Function with arguments: function functionName(arg1: Type1, arg2: Type2, ...): ReturnType { ... }
// Function with named arguments: function functionName({arg1, arg2, ...}: {arg1: Type1, arg2: Type2, ...}): ReturnType { ... }