Introduction to TypeScript

TypeScript is a superset of JavaScript developed by Microsoft that supports classes, modules and interfaces, along with several other features. It is a static type language, meaning it will validate code at development time. JavaScipt is a dynamic language, which does not validate code at development time. Having a static type language is very useful for building robust code. To try out TypeScript online, go to www.typescriptlang.org and select Playground: You will … Continue reading Introduction to TypeScript

JavaScript – Calling Functions

Let’s go through an example of different ways to call a function in JavaScript. Let’s say we have a function that prints Hello World to the console. We can call this as: function HelloWorld() { console.log(“Hello World”); } HelloWorld(); This function can also be assigned an anonymous variable and called as below: var i = function() { console.log(“Hello World”); } i(); Or also run immediately as: var i = function() … Continue reading JavaScript – Calling Functions

JavaScript – Use Strict

“use strict” is a feature of JavaScript that tells the compiler to use a strict context. For example, consider the code below. This code produces no errors, and displays “1” in the console: However, let’s say we didn’t include “var” before our variable. In normal JavaScript without using “use strict”, this would be fine. However, with “use strict”, it throws an error: For more information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode  

JavaScript Resources

Libraries Angular React Node Vue Redux jQuery Ember Meteor Visualizations GoJS D3 Leaflet  

JavaScript – Object defineProperty

In JavaScript, there are different ways to define properties to objects. For example, if we have a Customer class, we can define properties using the this keyword, and also Object.defineproperty: function Customer (firstname, lastname, email, phonenumber) { this.firstname = firstname, this.lastname = lastname, this.email = email, Object.defineProperty(this, “phonenumber”, { writable: true, enumerable: true, configurable: false, value: phonenumber }); } //Print out Customer var Customer00001 = new Customer(“Bob”, “Smith”, “bob@test.com”, “111-222-7777”) … Continue reading JavaScript – Object defineProperty

JavaScript Object Literals

Object literals are a way to define objects in JavaScript using comma-separated name-value pairs of properties and methods. For example, we can define a Customer object with the syntax, which contains properties and a method GetCustomer(): var Customer = { firstname: “Bob”, lastname: “Smith”, email: “bsmith@test.com”, phonenumber: “555-111-2222”, GetCustomer: function() { return this.firstname + ‘ ‘ + this.lastname + ‘ ‘ + this.email + ‘ ‘ + this.phonenumber; } } … Continue reading JavaScript Object Literals

Installing a Node Web Server using http-server

Node has several web servers available for installation, including http-server: To install, type: npm install http-server -g To start the server, type: http-server This will start the web server at the addresses: Opening a web page at this address will display the contents of the current directory: If we create a folder called webserver with one file, index.html, and browse to this directory, we see the index file is displayed: … Continue reading Installing a Node Web Server using http-server