Illustrative apprehension in JS
-
I just started studying JS. The python taught before. There were lines in the python.
name_var: int
orname_var: str
♪ These lines tell us thatname_var
Type of dataint
orstr
respectively. Or PostgreSQL.name_var::int
orname_var::text
♪ What about JS? As I am to point out, I expect the exact meaning of the function. Or how I compare the variables as I did in the python because of the function.isinstance()
♪
-
There JavaScript is no such thing as strict typing, you can check the type.
typeof(variable) === "string"
for simple variables orobjectVar istanceof Array
for objects.function MyClass(name) { if (!(this instanceof MyClass)) throw new Error("Sorry not an class"); if (typeof(name) !== "string") throw new Error("First param must be string"); this.name = name; }
MyClass.prototype.getName = function() {
return this.name;
}
There's also a superstructure on JS, very often used in large projects, and active support is JavaScript Community - TypeScript. https://www.typescriptlang.org/ ♪
function Hello(name: string): number {
console.log("Hello ", name);
return 1;
}