Basic JavaScript Interview Questions
JavaScript Basics: Basic JS Questions
What is JavaScript?
View Answer:
Interview Response: JavaScript is a high-level, dynamically typed, interpreted scripting language used to create interactive effects in the browser or server.
note
It should be noted, to maintain efficient speed in the browser, V8 translates JavaScript code into more efficient machine code instead of using an interpreter. During execution, it compiles JavaScript code into machine code using a JIT (Just-In-Time) compiler, much like SpiderMonkey or Rhino in the Mozilla browser.
What is the difference between a high-level and low-level programming language?
View Answer:
Interview Response: A high-level language gets compiled without detailed knowledge of the underlying computer. For example, managing memory, knowing what processor is running, and keeping track of things like pointers are not necessary. High-level languages are more accessible to write and manage than low or mid-level programming languages because they are platform-independent. The major distinction between high-level and low-level languages is that programmers can readily grasp, interpret, and compile high-level languages when compared to machines. Machines, on the other hand, can interpret low-level language more readily than humans.
Is JavaScript an interpreted or compiled programming language?
View Answer:
Interview Response: JavaScript is an interpreted language.
Technical Response: In a compiled language, the target machine directly translates the program. The target machine does not translate the source code directly into an interpreted language. Instead, a different program, an interpreter, reads and executes the code. In simple terms: JavaScript is an interpreted language.
What is the name of the JavaScript scripting language specification called?
View Answer:
Interview Response: ECMAScript with a reference guide named ECMA-262.
Why is it called JavaScript?
View Answer:
Interview Response: JavaScript was initially named "Live Script," but because of the popularity of Java. It was renamed too JavaScript as a play on the notoriety of the Java programming language, but they are considerably different. JavaScript is a high-level programming language, and Java is a mid-level programming language.
On which platforms can we implement JavaScript?
View Answer:
Interview Response: JavaScript works in any environment that has a JS engine.
Technical Response: Today, JavaScript can execute not only in the browser but also on the server or any device with a unique JavaScript engine like Node.js.
What are the code names for Chrome, Opera, FireFox, IE, Edge, and Safari?
View Answer:
Technical Response:
- V8 - in Chrome and Opera
- Spider Monkey - in FireFox
- Chakra - in Internet Explorer
- Chakra Core - in Microsoft Edge
- Nitro / SquirrelFish - in Safari
Why is it good to remember code names for different JavaScript Engines?
View Answer:
Interview Response: It is good to remember the names of engines to ensure features work in all environments. If not, we must write a polyfill.
Technical Response: The code names are good to remember because they get used in developer articles on the internet. For instance, if "V8 supports a feature X, " it probably works in Chrome and Opera.
What can in-browser JavaScript do?
View Answer:
Interview Response: In-browser JavaScript can do everything related to a webpage like manipulation, interaction with the user, and the webserver.
Technical Response: JavaScript's capabilities get heavily influenced by the environment in which it runs. Node.js, for example, includes methods that allow JavaScript to read/write arbitrary files and make network requests.
In-browser JavaScript can accomplish everything related to webpage alteration, user interaction, and webserver interaction.
In-browser JavaScript can accomplish everything related to webpage alteration, user interaction, and webserver interaction.
For instance, in-browser JavaScript can:
- Modify the existing text, add HTML, and design the page.
- Respond to user activities, such as mouse clicks, pointer movements, and keystrokes.
- Send network requests to distant servers and download and upload files (so-called AJAX and COMET technologies).
- Get and set cookies, ask the visitor questions, and display messages
- Track client-side data ("local storage").
What CAN'T in-browser JavaScript do and why?
View Answer:
Interview Response: JavaScript's abilities are limited to ensure a user's safety in the browser. The aim is to prevent a malicious website from accessing users' data or harming them.
Technical Response: JavaScript's capabilities in the browser are limited to safeguard the user's safety. The purpose is to prevent a malicious website from acquiring private information or inflicting data damage to users.
Examples of such constraints include:
- JavaScript permits us to read/write files directly on the hard disk, copy them, or run applications on a web page, however, it does not have direct access to OS functionality.
- Modern browsers allow it to interact with files. Still, access is limited and only provided if the user performs specific actions, such as "dropping" a file into a browser window or choosing it through a tag.
- Interacting with the camera/microphone and other devices is possible, but it requires the user's explicit consent. The JavaScript-enabled page may not secretly activate a web camera, examine its surroundings, and communicate the data.
- JavaScript from one page may not be able to access JavaScript from another if they are from separate sites (from a different domain, protocol, or port).
- JavaScript can easily connect with the server that serves the current page through the internet. However, its capacity to receive data from other sites/domains is severely limited. Although feasible, it requires explicit agreement from the remote side (represented in HTTP headers).
What makes JavaScript unique?
View Answer:
Interview Response: JavaScript is unique because it fully integrates HTML and CSS, and all major browsers support it. JavaScript is the only browser technology that combines all three of these features. That distinguishes JavaScript and explains why it is the most widely used technology for designing browser interfaces.
Name some modern alternative languages that convert to JavaScript?
View Answer:
Interview Response: Some of the alternatives to JavaScript include Coffee Script, TypeScript, Flow, Brython, Dart, and Kotlin.
Technical Response: Several popular languages are trans-piled (converted) to JavaScript before running in the browser.
Examples of such languages:
- CoffeeScript is a "syntactic sugar" for JavaScript. It introduces shorter syntax, allowing us to write more transparent and more precise code—usually, Ruby devs like it.
- TypeScript concentrates on adding "strict data typing" to simplify the development and support of complex systems, and Microsoft develops it.
- Flow also adds data typing, but differently, and Facebook developed it.
- Dart is a standalone language with an engine that runs in non-browser environments (like mobile apps) and converts to JavaScript—developed by Google.
- Brython is a Python transpiler to JavaScript that enables the writing of applications in pure Python without JavaScript.
- Kotlin is a modern, concise and safe programming language that can target the browser or Node.