Colon after function declaration in javascript

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

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

      

Can someone explain to me what is called this function declaration?

+3


source to share


1 answer


This is a type declaration. :boolean

means that the function isStringStart

should return a value boolean

. It's the same with the argument type declaration. chr: number

means that the function takes one argument, which must be typeof number.



If the requirements are not met (no valid arguments are passed or the wrong value is returned), the type checking library you are using will throw an error.

+3


source







All Articles