Introduction to JS

What is JavaScript?

  • JavaScript is a dynamic, weakly typed programming language which is compiled at runtime.
  • It can be executed as part of a webpage in a browser or directly on any machine (“host environment”).
  • JavaScript was created to make webpages more dynamic (e.g. change content on a page directly from inside the browser).
  • Originally, it was called LiveScript but due to the popularity of Java, it was renamed to JavaScript.
  • JavaScript is totally independent from Java and has nothing in common with Java!

A Brief Overview Of The JavaScript History

  • 1995 –> Netscape introduces LiveScript/JavaScript
  • 1996 –> Microsoft releases its own version for IE
  • Late 1996 –> JavaScript submitted to ECMA International to start standardization
  • 1997 - 2005 –> Standardization efforts, Microsoft didn’t really join and support the standardized JS version though
  • 2006 - 2011 –> Huge progress in JavaScript ecosystem, Microsoft eventually joined forces

ECMA & Javascript

  • ECMAScript is the standard, JavaScript the language in practice
  • Previously known as European Computer Manufacturers Association(ECMA)
    • Renamed ECMA --> Ecma
    • An organization that creates standards for technologies
  • Browser vendors implement the standard into their JS engine.
  • ES6/ES2015
    • (ECMAScript 2015) was released which is the biggest update to the language ever!
    • ES6(and newer) terms as Modern JavaScript
  • Old features are never removed, Backward compatible, Not Forward compatible

FAQ

  • How Is JavaScript Executed?
  • JavaScript Runs On A Host Environment
  • Dynamic? Weakly Typed?
  • JavaScript and Java
    Page: /

How Is JavaScript Executed?

  • Js code is executed by Javascript Engine
  • Parse > Compile > Execute code
  • On a single Thread
  • JS Engine Built in Browser
    • V8 - Chrome
    • SpiderMonkey - Firefox

Google’s JavaScript Engine (V8) was extracted to run JavaScript anywhere (called Node.js)

  • JavaScript is single-threaded: “One thing happens at a time”
  • HEAP
    • Memory allocation
    • Stores data in your system memory and manages access to it
  • Stack
    • Execution Context
    • Manages your program flow (function calls and communication)

Dynamic? Weakly Typed?

  • JavaScript is dynamic type language
    • We don’t specify types in advance, the object types is resolved at runtime.
  • Weakly Typed Programming Language
    • There is implicit type conversion
    • 9 + ‘9’ –> “99” Not Error

JavaScript and Java

  • Totally independent programming languages with different syntax and principles
  • JavaScript was named JavaScript to ”sound cool”
  • Java does NOT run in the browser, JavaScript does

Working with console

  • Press F12 (or Right click + inspect) for console in browser
// Log to console
console.log('Hello World');
console.log(123);
console.log(true);

console.log([1,2,3,4]);
console.log({a:1, b:2});

console.table({a:1, b:2});  // Table

console.error('This is some error');
console.warn('This is a warning');

// Single line comment
/* multi  line
  comments
*/

// timer start
console.time('Hello');
// timer end
console.timeEnd('Hello');

// console.clear(); 

Reference