What Is Javascript?
We can’t go very far in tech without running into javascript-whether it’s the scripting language used to create 2D/3D graphics on YouTube or the dynamic content updates on your Facebook feed. But what exactly is javascript, and does it actually matter?
Developed by Netscape for its early versions of the World Wide Web, javascript is an object-oriented programming language that has become a cornerstone of modern browser functionality. Designed to help make websites more interactive and engaging, it’s been adopted by virtually all modern web browsers and is now an essential tool for building complex web applications.
All modern web browsers include a built-in javascript engine that is able to interpret javascript code and execute it. When a page comprising js script is loaded the engine converts the code into an abstract syntax tree (AST) and then into machine code before finally rendering it on the screen. This process is often referred to as compilation.
In order to work with a webpage, the js engine needs to interact with its parent element which is known as DOM. The DOM is a programming interface for web documents that represents their structure as a tree, which can be manipulated by javascript to change HTML elements and CSS styles, as well as to respond to user interactions dynamically.
Another key aspect of javascript is that it’s a dynamically-typed language. Unlike static languages, like C or Java, which have specific data types for values, variables in javascript are treated as hashes where property keys can be added, deleted, re-ordered, mutated and dynamically queried at run-time. Arrays in javascript are also dynamically typed, with properties indexed either by using dot notation (.) or square brackets ([]). Values can be cast to strings and numbers through the toString and valueOf functions.
Functions in javascript can take 0 or more parameters and return a value at any time, terminating the function. They can also declare their own variables which are local to the function, and they can use a range of numeric operators such as +, -, *, /, and % (remainder) to perform addition, subtraction, multiplication and division.
Javascript offers advanced features that can be used to build more complex web applications, including event handling, asynchronous programming, and syncing data with back end servers. Among other things, these can be used to create drop down menus, enable form validation, and display real-time data updates on a website.
As you start learning javascript, the best way to get your feet wet is by using a web console, such as the one shown in the screenshot above for Firefox. All modern web browsers come with a web console that works in a similar fashion and allows you to enter javascript code that will be executed on the page when you press enter.