General Flashcards
When creating a Number object, what do passed values that can’t be converted return?
NaN
What error types does JavaScript have?
As well as the generic Error object JavaScript offers other error constructors tailored to specific errors.
RangeError - creates a RangeError instance that occurs when a numeric variable or parameter is outside of its valid range.
ReferenceError - creates a ReferenceError instance when trying to dereference a non-existant variable.
TypeError - creates a TypeError instance that occurs when a variable or parameter is not of a valid type.
URIError - creates a URIError instance that occurs when URI handling functions are passed malformed URIs.
What is a binding?
A binding is the combination of a name (like a) and a storage slot for its current value. Variables are bindings. So are constants, parameters, the variable created by a function declaration, and various built-in things like this.
What does mutable mean?
A mutable value is one that can be changed without creating an entirely new value. In JavaScript, objects and arrays are mutable by default, but primitive values are not — once a primitive value is created, it cannot be changed, although the variable that holds it may be reassigned.
What types are mutable and what are not?
Mutable: arrays, objects.
Non-mutable: primitive values
What are the two types of values in JavaScript?
Primitive types and reference types.
List out the primitive types
Strings, numbers, null, undefined, symbols, bigInt, booleans
List out the reference types
Arrays, objects, functions
What is a reference type?
Reference Value: JavaScript provides three types of Reference values that include Array, Object, and Function. The size of a reference value is dynamic therefore It is stored on Heap. When we access a reference value, we manipulate it through reference, not through its actual value that is stored.
What are the two types of modules?
CommonJs and ECMAScript Harmony (ES6)
What are the two types of module exports in JavaScript?
Every module can have two different types of export, named export and default export. You can have multiple named exports per module but only one default export.
What does __proto__ signify?
__proto__ represents the [[Prototype]] of the object
The __proto__ getter function exposes the value of the internal [[Prototype]] of an object.
However the use of __proto__ is controversial and discouraged.
const o = {
a: 1,
b: 2,
__proto__: {
b: 3,
c: 4,
},
};
What is [[Prototype]]? or someObject.[[Prototype]]?
someObject.[[Prototype]] is used to designate the prototype of someObject.
The [[Prototype]] internal slot can be accessed and modified with the Object.getPrototypeOf() and Object.setPrototypeOf() functions respectively.
This is equivalent to the JavaScript accessor __proto__
How do you set obj1 to be the prototype of obj2?
let obj1 = {
prop1: ()=>console.log(‘prop1’)
}
let obj2 = {
prop2: ()=>console.log(‘prop2’)
}
Object.setPrototypeOf(obj2, obj1);
obj2.prop2();
obj1.prop1();
therefore
const obj2 = {
prop2: () => console.log(‘prop2’),
__proto__: {
prop1: () => console.log(‘prop1’),
}
}
How do you find the prototype of an object?
Object.getPrototypeOf(obj2);
will equal: obj1
How do discern between the properties of an object and its prototype?
Object.getOwnPropertyNames(obj2)
will return prop2
What is a Runtime Environment?
A runtime environment is where your program will be executed. It determines what global objects your program can access and it can also impact how it runs.
What are the two JavaScript runtime environments:
The runtime environment of a browser (like Chrome, or Firefox) and this is called an ‘engine’
The Node runtime environment
Why was node created?
The Node runtime environment was created for the purpose of executing JavaScript code without a browser, thus enabling programmers to create full-stack (front-end and back-end) applications using only the JavaScript language.
Why is the noderun-time environment different from the browser?
The Node runtime environment gives back-end applications access to a variety of features unavailable in a browser, such as access to the server’s file system, database, and network.
What is process.env? As in process.env.PWD?
process.env is an object containing environment variables such as process.env.PWD which contains the current working directory
Is Node a framework!
So Nodejs is not a framework (or a language) but a JavaScript runtime built on Chrome’s V8 JavaScript engine.
Is Node.js Single-threaded and is it Synchronous or Asynchronous?
Node.js is Single-threaded and Asynchronous.
In the browser how does the event loop operate with setTimeOut?
Whenever an async function is called, it is sent to a browser API. These are APIs built into the browser. Based on the command received from the call stack, the API starts its own single-threaded operation.
Therefore when a setTimeout is called, it is processed in the stack and then sent to the corresponding API which waits till the specified time to send this operation back in for processing.
How is node asynchronous?
Node can create multiple threads, but only one thread is dedicated to parsing and executing javascript code.
The other threads are started from C++ bindings called from the JS.