What does the colon mean after a function and what does the parameter mean after that?

Hello, i looked into code of others and saw that some people were using some type of colon and parameters after defining their functions, something like this:

 Test.TestFunction = function() : any

end

I wanted to know what that means and is it important to use it?

2 Likes

I’m pretty sure it just tells you what the function return so in the case of the function in your post, it returns any datatype and it’s only important to use when I guess you wanna know what a function should return explicitly

1 Like

That is type checking and in the specific code you have given it means the function can return any type of value. Type checking is used in order to ensure the correct data types are being used and also makes bug fixing easier.

Here is another example of type checking:
This example shows a function where 2 numbers are being added together, if someone attempts to input a string into the function it will error.

local function addNumbers(num1: number, num2: number): number
          return num1 + num2
end
1 Like

Thank you for helping me, i understand it now!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.