nodejs specify class type in function code example
Example 1: javascript class
class ClassMates{
constructor(name,age){
this.name=name;
this.age=age;
}
displayInfo(){
return this.name + "is " + this.age + " years old!";
}
}
let classmate = new ClassMates("Mike Will",15);
classmate.displayInfo(); // result: Mike Will is 15 years old!
Example 2: parameters types in javascript
/**
* My function description
* @param {String} a
* @param {String} b
* @param {Number} amount
* @example
* // returns "fooBar fooBar"
* myFunction('foo', 'Bar', 2)
* @returns {String}
*/
function myFunction(a, b, amount){
//do stuff
}
//Note that javascript is not a statically typed language and therefore you
//will not recieve any syntax errors for passing in the wrong types.
//The above code works in Visual Studio Code and intellisense.