So what is JavaScript anyway? I’m actually confused 😮💫

Bouncing iron eggs
6 min readAug 28, 2021

Preface

To quote from JavaScript Advanced Programming, Fourth Edition — “From simple input validation scripts to a powerful programming language, the rise of JavaScript was not predicted by anyone. It's simple enough to learn to use in minutes, and complex enough to take years to master. To really learn to use JavaScript well, it is important to understand its nature, history and limitations".

Interviewer: What is JavaScript?

Me: em… JavaScript is JavaScript... 👀

Imagine if an interviewer asked you: ‘What is JavaScript?’ What would you answer? To be honest, my mind went blank for a moment when I heard this question. We’ve been studying front-end for so long, Even the simplest question, “What is JavaScript?” can’t even tell the interviewer what it is right away. Today we’re going to talk about what you can do when an interviewer asks you what JavaScript is, and what you can do to say as much as possible and make a good impression.

What is the position of JavaScript?

1. JavaScript is a scripting language

Why a scripting language? Let’s take a brief look at the history of the introduction of JavaScript. In a nutshell, in 1995 Netscape introduced a client-side scripting language called JavaScript to solve the problem of client-server communication delays during simple form validation on a page and had great success at the time. This was when Microsoft decided to devote more resources to IE, targeting JScript, and then Ecma (European Computer Manufacturers Association) introduced ECMAScript (pronounced "ek-ma-script"), an international standardisation of the two languages, to address the coexistence of the two versions.

What can a scripting language do? It can perform complex functions on the web, including manipulating DOM elements on the page, CSS styles, interactive maps, 2D/3D animations, scrolling videos and much more. JavaScript is very powerful and flexible in its host environment, giving developers many more possibilities.

2. JavaScript is a weakly typed language

This means that variables can be implicitly converted to another type. The hidden conversion of types gives JavaScript some flexibility, but it also increases the complexity of the rules and the likelihood of errors.

  • The binary operator + converts two operands to strings, unless both operands are of type numeric. This is because + can also be used to concatenate strings.
  • The binary operator - converts two operands to a numeric type.
  • The unary operators, including + and -, convert operands to numbers
console.log(1 + '2' === '12')
// true
console.log('3' - '1' === 2)
// true
console.log(+'1' === 1)
// true
console.log(-'1' === -1)
// true

3. JavaScript is dynamically typed

let a = 233
a = 'Bouncing iron eggs'
console.log(a)
// 'Bouncing iron eggs'
eval("console.log('Bouncing iron eggs')")
// 'Bouncing iron eggs'

4. JavaScript is single-threaded

JavaScript needs to interact with the page, manipulate the DOM, etc., and if it is multi-threaded, this can present a very complex synchronisation problem. For example, suppose JavaScript has two threads at the same time, and one thread adds content to a DOM node and the other thread deletes it, which thread should the browser take? So this dictates that it can only be single-threaded.

5. JavaScript Interpreted languages

Interpreted language is a type of programming language. It is a type of programming language where the code is run one sentence at a time, without the need to be compiled into machine code by a compiler, as is the case with the Compiled language.

6. JavaScript is well cross-platform

Cross-platform features, with support in most browsers, and can run on a wide range of platforms (e.g. Windows, Linux, Mac, Android, iOS, etc.).

What is the difference between JavaScript and ECMAScript and how does it relate to the DOM and BOM?

Let’s start with a brief overview of the concepts of ECMAScript, DOM and BOM.

DOM

DOM (Document Object Model), provides methods and interfaces for interacting with the content of a web page. The DOM abstracts the entire page into a set of hierarchical nodes. Each component of an HTML or XML page is a node of sorts, containing different data. The DOM allows the developer to control the content and structure of a web page as they wish by creating a tree that represents the document. Using the DOM API, nodes can be easily removed, added, replaced and modified.

<html>
<head>
<title>Sample Page</title>
</head>
<body>
<p> Hello World!</p>
</body>
</html>

BOM

The BOM (Browser Object Model), provides methods and interfaces for interacting with the browser. The BOM is mainly for browser windows and sub-windows (frames). Using the BOM, developers can manipulate the browser to display parts of the page other than the page, for example

  1. The ability to pop up a new browser window;
  2. the ability to move, zoom and close the browser window;
  3. The navigator object, which provides detailed information about the browser;
  4. The location object, which provides detailed information about the page the browser is loading;
  5. screen object, which provides detailed information about the user's screen resolution;
  6. performance objects, which provide detailed information about the browser's memory usage, navigation behaviour and time statistics;
  7. Browser storage related operations such as cookies, sessionStorage, localStorage, etc;
  8. other custom objects, such as XMLHttpRequest and ActiveXObject for IE.

ECMAScript

ECMAScript describes the syntax and basic objects of JavaScript: 1) syntax; 2) types; 3) statements; 4) keywords; 5) reserved words; 6) operators; 7) global objects.

ECMA publishes the first version of the standard document 262 (ECMA-262), which specifies a standard for browser scripting languages and calls this language ECMAScript, which is version 1.0, so in a nutshell, ECMAScript is a set of specifications and JavaScript is an implementation of ECMAScript is an implementation. Why is it an implementation? Because Adobe ActionScript also implements ECMAScript, and JScript also implements ECMAScript.

Relationships

So after a brief understanding of these key concepts it’s easy to see how they relate to each other! In JavaScript Advanced Programming, Fourth Edition, there is a diagram that describes the relationship between JavaScript, ECMAScript, DOM and BOM very clearly.

We conclude that ECMAScript, DOM and BOM are integral parts of JavaScript.

Summary

So at the end of the article, when the interviewer asks “What is JavaScript?”, we know where to start and what to start with. So if we’ve made all the points in this article clear to the interviewer, I’m sure we’ll be able to leave a good impression without making a bad one 😋

Positioning of JavaScript

  • JavaScript is a scripting language
  • JavaScript is a weakly typed language
  • JavaScript is dynamically typed
  • JavaScript is single-threaded
  • JavaScript is an interpreted language
  • JavaScript is well cross-platform

the difference between JavaScript and ECMAScript and the relationship with DOM and BOM

  • DOM (Document Object Model), which provides methods and interfaces for interacting with web content
  • BOM (Browser Object Model), which provides methods and interfaces for interacting with the browser
  • ECMAScript which describes the syntax and basic objects of JavaScript.

Finally, to quote the opening paragraph, “To really learn to use JavaScript well, it’s important to understand its nature, history and limitations”.

--

--