Skip to main content

Introduction

What is JavaScript

It is a scripting language that is the core of websites, along with HTML and CSS, by learning scripting language you give interactivity to your web pages!

Sliders, alerts, click interactions, popups, etc... Are all made possible with JavaScript!

NodeJs and Chrome Browser

Today, JavaScript also execute outside of browsers! JavaScript can be used with Nodejs to write server-sided code!

In fact, any device that has a JavaScript engine is able to execute JavaScript. i.e. V8 in Chrome, SpiderMonkey in Firefox.

So browser and the like provide an environment that the JavaScript can be executed by the JavaScript engine underneath. Nodejs is also an environment that can execute JavaScript!

What in-browser JavaScript can/can't do

It is able to do the following

  • Add new HTML to the current web page, change its content that's within the tag
  • Handle user events, such as mouse clicks, mouse movements, and key presses
  • Send request over the network to other servers and get the result back, this is AJAX/XMLHTTPRequest object
  • Get and set cookies, and use client-side storages

However, because in-browser is meant to be safe it's ability is also limited in order to protect the user's safety

  • It cannot read any arbitrary files on hard disk, has no direct access to OS functions, can't read or write the arbitrary files
  • Different tabs are isolated via "Same Origin Policy", the JavaScript of one webpage cannot sniff and peak into the webpage of another, i.e. retrieving and stealing cookies

Languages on top of JavaScript

Since JavaScript is a scripting language, the syntax might not be for everyone since everyone's need is different.

Therefore, a bunch new language is created, that is ultimately transpired (converted) back to JavaScript before they run. The transpilation process is fast which make them usable.

  1. Coffeescript: A syntactic sugar for JavaScript that have bunch of shorter syntax for writing shorter and cleaner JavaScript code
  2. TypeScript: Adds strict data typing and typing into JavaScript
  3. Flow: Also adds data typing but in a different way compared to TypeScript
  4. Dart: Is a standalone language that has its own engine and can also be transpiled into JavaScript
  5. Kotlin: Can be run in browser or Node

Many example of languages that are developed on top of JavaScript