JavaScript's Place In Computer Science
Published: 2021-08-24 18:03:44

### What is Javascript?

Javascript is a programming language that allows you to write complex code on and off the web. 

Javascript is used for displaying updates, interactive maps, 2D and 3D animations, etc 

Javascript is the third layer of website creation

1. HTML for the structure 
2. CSS for the design and beauty 
3. JavaScript for Interaction 

### How does Javascript Work?

**Runtime environment:** A run-time environment is a program where your code goes in and the result of your code comes out. think of it as a Tesla factory. metal, wires, leather, etc goes in on one end and a car comes out the other. inside the factory, you have everything you need to change the metal, wires, leather, etc into a functioning electric car. 

**Javascript** has two **run-time environments**

1. Browser run-time environment 
2. The Node run-time environment 

The **Browser run-time environment** is the most common environment javascript is run on. Every modern browser comes with this environment.  since 2009, it was the only way to run javascript code. 

The **Node run-time environment** was created in 2009 to run javascript outside of the browser. This means, you no longer need to download a browser to use javascript. 

Modern JavaScript Development is divided into two 

**Client-side / Front-end:** uses the **Browser run-time environment.** When you visit a website, your computer requests raw HTML, CSS, and JS files from the server. When your browser receives these files. it uses its built-in run-time environment to change the JavaScript code to activities you can observe on your browser.

**Server-side / Back-end:** uses **The Node run-time environment.** when you visit a website which uses **JavaScript,** your code is handled and run by the downloaded **node-environment on that server (Computer).** you can download this environment from [nodejs.org](http://nodejs.org/) if you want.

As you might have noticed all websites are basically the same except in content and how it is displayed. every website has a header, navigation, buttons to click on, etc. This means each developer had to start from a blank page and built everything themselves each time. to solve this problem and make building websites more secure, faster, and easier developers build **Application Programming Interfaces (APIs)** which provide you with extra superpowers to use in your JavaScript code.

There are two sets of **APIs** for each **Environment.** built-in APIs and Third-party APIs

Browsers come with built-in APIs called **Browser APIs,** they provide access to the surrounding computer environment and do some other tasks. some examples are:

The DOM (Document Object Model) API allows you to manipulate HTML and CSS, dynamically changing the style of the website as you go through.

The Geolocation API gives you access to the client's geographical information. This is how you can use maps on websites.

The Canvas and WebGL APIs enable you to create 2D and 3D animations on websites.

Audio and Video APIs give you the ability to play music, watch a video and access your camera on the website. 

The outside developer community also wrote their own APIs called **Third-Party APIs** and these APIs give access to more capabilities for example:

Google Maps API lets you embed custom maps on your website 

Stripe APIs let you embed payment systems into your website 

Node also has both built-in APIs and third-party APIs

File System Module is a built-in module that handles file management in back-end javascript. creating files, reading files, deleting files, etc.

HTTP is a built-in module for connecting to another computer over the network using the HTTP protocol.

ExpressJS is a third-party package that makes it easy to create back-end servers with nodejs. it also does many other things.

MongooseJS is a third-party package that makes it easy to connect MongoDB database to your node server.



### Is Javascript Interpreted or Compiled Language, and What is the difference?

**Interpreted languages:** Every line of the code is **translated** from human-readable form to machine code just before it is run (**Just-in-time compilation**).  eg. Python, **JavaScript**, Ruby

**JavaScript** is interpreted language

**Compiled languages:** All the code is **compiled** from human-readable form to machine language beforehand and then is run **(Ahead-of-time compilation)**. C, C++, GO