Introduction to JavaScript & Data Types Flashcards
What is a runtime environment and its use?
A runtime environment turns an application from a set of instructions into something that can do actual work.
It is an execution environment that allows an application program to access the machine’s system resources such as networking infrastructure, RAM, sensors, or GPU.
It provides the tools the application needs to let the operating system understand what it is doing and interact with the outside world.
What is the purpose of compilers and interpreters? What’s the difference between the two?
Compilers and interpreters help convert programming languages into a form that the computer can understand (e.g. ones and zeroes).
Compilers produce an output file that the computer can run directly.
Interpreters run the interpreted code directly instead of translating it into 1s and 0s.
What type of compiler/interpreter do most modern JS engines use?
JavaScript is an interpreted language. However, most modern JS engines employ a special type of compiler called Just In Time (JIT) compiler.
JIT compiler is a way of executing code that involves compilation DURING the execution of the program.
i.e. compiles the code while the programming is running rather than before.
What is an API and how is it related to a runtime environment?
An API describes the scheme (plan) and format that a programmer can use to securely access an operating system’s resources.
The compiler/interpreter and the OS’s APIs together make up a runtime environment. They provide the tools that an application needs to run.
What are JavaScript’s major runtime environments?
The browser (frontend) and Node.js (general).
How does Javascript interact with the web browser?
The web browser is JavaScript’s original and dominant runtime environment. Almost every browser has a JS engine built into it.
JS interacts with the DOM API to manipulate the structure and appearance of a web page.
JS also interacts with the XHR (XMLHttpRequest) interface and the Fetch API to communicate with a server.
What is Node.js? How was it developed? What does it allow JS to do?
Node.js is a runtime environment that turns JS into a general-purpose programming language that can run applications on almost any system.
Node.js allows Javascript to:
(1) Read/write disk files (disk I/O)
(2) Read/write via the terminal (standard I/O)
(3) Send/receive messages over a network (network I/O)
(4) Interact with a database
The creators of Node.js took the open-source Chrome V8 JS engine and added APIs and tools required for desktop and server computing.
What are Javascript’s two types of methods?
Instance and static methods.
Instance methods uses String.prototype.method() and requires an object of its class to be called.
e.g.
> ‘Hello, ‘.concat(‘Bob!’)
> ‘Hello, Bob!’
Static methods uses String.method() and does not require creating an object of its class.
e.g.
> String.fromCharCode(97)
> ‘a’
What are the 7 primitive data types?
String, Boolean, Number, Null, Undefined
Symbol and BigInt were introduced in ES6, not used often
What is the usage of the backslash character?
The backslash, or escape character (), tells the computer that the next character isn’t syntactic, but part of the string.
What is the difference between undefined and null data types?
Null and undefined both represent an absence of a value, but null is an INTENTIONAL absence, usually assigned by design.
How does JavaScript implicitly coerce with the == non-strictly equal operator?
When comparing numeric and non-numeric values with the non-strictly equal operator ==, JS will coerce the non-numeric value (string, booleans) to numeric.
e.g. > 1 == true // true because true will be coerced into a number
e.g. > undefined == null // true because 0 == 0
What is the difference between explicit and implicit type coercion?
Explicit type coercion lets you decide what to do with the data type whereas implicit coercion lets the JS engine choose.
e.g. Explicit coercion ‘1’ + ‘2’
> Number (‘1’) + Number (‘2’) = 3
// changes string to number
e.g. Implicit coercion ‘1’ + ‘2’
> ‘1’ + ‘2’ = ‘12’
What is an expression? A statement?
An expression is anything that Javascript can evaluate to a value, even if the value is undefined/null.
Statements refer to syntactic unit of code that expresses an action for the computer to perform. Statements always evaluate as undefined. e.g (console.log). In practice, most programmers use the term statement rather loosely.
Expressions can be part of a statement, but not all statements are expressions.
What do identifiers refer to in JS?
Variable names (let and var) Constant names (const) Objects' property names Function names Function parameters Class names