Array with different types of data? Weird stuff! Generally, an array is collection of similar items. In Computer Science 101, this means the items are of the same data type. We have an array of integers, boolean values or strings. But in JavaScript, arrays can have elements of different types.
Type Checking in JavaScript
Okay, JavaScript is a loosely-typed language, which means you do not declare the data type of a variable explicitly. In a basic variable assignment expression, e.g., var i = 4;, the value that assigns to the variable determines the data type of the variable. As you assign different types of data to the same variable, its data type changes as well. Given the nature of JavaScript, finding out what data type a variable represents before using it is very important.
JavaScript Object Creation and Object Methods and Properties
[wp_ad_camp_1] If you’ve read this, it merely declares JavaScript can do OOP. It did not talked about other (more advanced) OOP stuff like access modifiers, encapsulation – behaviors and properties, and inheritance. On this article, we’ll talk more on object
JavaScript Static Properties and Methods
In JavaScript Object Creation and Object Methods and Properties, we talked about methods and properties that are tied to an object. Without an object, these properties are unusable and inaccessible to other codes. There is another type of members – static methods and properties. These are only accessible via the class itself. These are even inaccessible if referenced via objects.
Inheritance in Object-oriented JavaScript
Inheritance in JavaScript is called prototypal inheritance. Objects inherit from objects. When we create an object from a class, [wp_ad_camp_5]
1 2 3 4 5 6 | function MyClass() { // The class }; var myObject = new MyClass(); |
it always inherits from
1 | MyClass.prototype |
In Java speak, this is like saying “any class inherits from Object class”.
1 2 3 | public class MyClass extends Object { ... } |
Convert TypeScript to JavaScript
This post demonstrate the basic process of converting TypeScript codes to JavaScript.