An Introduction to JavaScript


An Introduction to JavaScript
                                                    
          Image Bywww.tutorialrepublic.com
JavaScript is a programming language that was designed to make your static pages dynamic and responds to user events like button click, mouse events, etc. Basically, JS makes your HTML pages alive.

 
JavaScript follows an ECMAScript Specification that defines the standards that JavaScript has to follow. Earlier JavaScript was designed only to work on the browsers but using various JS libraries (like Node, Deno) can run the JavaScript on the server.

Actually, JavaScript can run on any device that has the JavaScript engine. Every browser has the JavaScript Engine that executes the JavaScript code in the browser. 


Examples of JavaScript engines:

  1. V8 Engine (Chrome browser)
  2. Spider Monkey (Firefox)


How JavaScript Engines Work?

The engine parses the Script and compiles it to the Machine code and then the machine code runs, pretty fast. The JavaScript engine applies optimizations at each step of the compilation process. It even watches the compiled script as it runs, analyzes the data that flows through it, and further optimizes the machine code based on that knowledge.



JavaScript can:

  1. Add a new Html code to the existing page 
  2. It can change the Existing content and styles as well.
  3. It can react to user events, like button clicks, mouse events, keypresses, etc.
  4. It can send requests over the network to the remote servers also upload or download files from the server.
  5. It can read or write browser cookies
  6. It can store the data on the client's local storage.

Note: JavaScript does not provide low-level access to memory, file system, or CPU for safety reasons because the JavaScript was Initially created for the browsers which do not require the low-level access. 

Node runtime environment gives JavaScript the ability to access the file systems, network, and memory.

JavaScript capabilities depend on the runtime it is executing on. Node provides the environment to access your file system, perform network requests, etc. But In-browser, JavaScript can only do activities related to the web page. 



Summary:
  • Initially, JavaScript was created for the browsers only but now it can run on the server using Node or Deno environment.
  • Using JavaScript you can create Web/Mobile apps, Real-time networking apps, command-line tools, and games.
  • JavaScript needs a Runtime environment to execute.