Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Colon after function declaration in javascript [duplicate]

Tags:

javascript

I am going through source code of Vue.js. In almost all the function declarations I find a new way of defining functions

function isStringStart (chr: number): boolean {
  return chr === 0x22 || chr === 0x27
}

Can somebody explain me what is this kind of function declaration called?

like image 967
Brijesh Prasad Avatar asked Jul 30 '17 14:07

Brijesh Prasad


1 Answers

That's a type declaration. :boolean means basically, that the isStringStart function must return a boolean value. The same with the argument's type declaration. chr: number means, that the function accepts one argument, which has to be typeof number.

If the requirements are not fulfilled (not proper arguments are passed or wrong value is being returned), the typechecking library you are using will throw an error.

like image 128
kind user Avatar answered Oct 14 '22 04:10

kind user