Illustrative apprehension in JS



  • I just started studying JS. The python taught before. There were lines in the python. name_var: int or name_var: str♪ These lines tell us that name_var Type of data int or str respectively. Or PostgreSQL. name_var::int or name_var::textWhat 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 or objectVar 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;
    }



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2