Advanced Search
Search Results
229 total results found
ActiveMQ
Artificial Intelligence Learning
Samba
Driver Study Notes
Functions, function expression, arrow function
Function Declaration To declare a function follow the syntax: function function_name(parameter1, parameter2, ..., parameterN) { // Body of the function } The function can have access to outer variable, as well as modifying it. The outer variable is only...
Objects and object references
Objects In JavaScript objects are used to store key to value pair collection of data. You can think of them as dictionary in Python. You can create an object using brackets { }, and a list of optional properties that the object will have. For example: let e...
Garbage collection
Reachability In JavaScript garbage collection is implemented through something called reachability. Variable that are reachable are kept in memory and not deleted by the garbage collector. A value is considered to be reachable if it's reachable from a root ...
Constructor and "new" operator
Constructor function Function that is meant to be a constructor are named with capital letter first and be executed with the new operator. We use a constructor because it creates a shorter and simpler syntax compared to creating object with {...} every time....
Optional chaining
Optional chaining There is this problem that if the object that you are accessing might or might not contain an object attribute say address and you can trying to access address's attribute further say user.address.street, then your JavaScript will crash beca...
Symbol Type
Symbols In JavaScript there is two primitive types that can be used as object property key String Symbol type Don't confuse the symbol type in Ruby with JavaScript they are different albeit similar in that they are used to create unique identifier. A ...
Arrays and methods
Array Two ways of creating empty array let arr = new Array(); let arr = []; Create an array with elements in them let arr = ["Apple", "Orange", "Plum"]; Array in JavaScript is heterogeneous, you can store element of any type in them. arr.length property...
Iterables
Iterables A generalization of arrays, it allows us to make any object iterable in the context of for ... of loop. Making an object iterable just requires you to add the Symbol.iterator hidden property which is a function that returns the iterator. Really dou...
Map and set, weakmap and weakset
Map Very similar to an object, however, with object the only key that is allowed is a String. Map on the other hand allows keys of any type. Any type as it ANY type, even an object can be used as a key new Map(): Creates a new empty map map.set(key, value...
Destructuring assignment
Destructuring assignment A special syntax to let us unpack either array or object into different variables Array destructuring let arr = ["Ricky", "Lu"] let [firstName, lastName] = arr; console.log(firstName); // "Ricky" console.log(lastName); // "Lu...
JSON
JSON file When you want to transport say a complicated object or an array of object to another compute using network. You cannot transport a complicated object just directly as "it is". You must serialize it which essentially turns the object into a stream of...
Miscellaneous function topics
Rest parameters and spread syntax How do we make a function take in an arbitrary number of arguments? Simple we use the ... rest operator in the function header. function sum(...args) { let sum = 0; for (let arg of args) sum += arg; return sum; } ...
Getters & setters
Virtual property In addition to the normal property that we have for objects, we can also set up virtual properties. They appears to the outside code as if they were the object's property but they are actually implemented as functions underneath. let user = ...
All about prototypes
Prototype inheritance Every object have a special hidden property [[Prototype]] it is either null or a reference to another object. Whenever you read a property from object and if it is missing, JavaScript will automatically take it from the prototype. Sett...
Classes in JavaScript
Class basic syntax Besides using a constructor function there is a more advance object oriented programming construct called class in JavaScript. The basic syntax is as follows: class MyClass { constructor() {} method1() {} method2() {} } To ut...
Try...catch
Syntax try { // Code } catch (err) { // Error handling } finally { // Excuted always, regardless if there is any error. And is always last // It is also executed right before you return if you decide to return/throw from try and catch } Keep ...
Promises and promise chaining
Time before promise, callbacks There are entities in JavaScript that let you schedule asynchronous tasks, tasks that you initiate first, then they will finish later. Task like disk reading, fetching resources from network that will take arbitrary amount of t...
More promise API
Promise.all This API will allow us to take in an iterable, an array of promises and return a new promise. That returned promise will only be resolved when all listed promises are resolved, the array of their results will become the result of this returned pr...
Async and await
async keyword async keyword is placed before a function like so: async function f() { return 1; } It basically make your function always returns a promise. If you didn't return a promise explicitly in the function they will be wrapped in a resolved promi...
All about modules
Two different standards In the browser JavaScript ecosystem, JavaScript modules depends on import and export statements to load and export ES modules. In addition, ES module is the official standard format to package JavaScript code for reuse. On the other ...