Warren Shea’s Notes for JavaScript (and TypeScript)
v20230104
Notable JavaScript Experts
Quick Reference
Terms
nullish
is null
or undefined
method
: a function inside an object
smooth brackets
or parenthesis
: ()
curly brackets
: {}
square brackets
: []
truthy
: a value accepted as true in a condition statement
falsy
: a value accepted as false in a condition statement
bang
: !
bang bang
: !!
, which converts a truthy to true or falsy to false
Conversions
NodeList to Array
[...NodeList]
or Array.from(NodeList)
Various Notes (no particular order)
Truthy/Falsy
In a conditional statement, these values are not true or false (boolean) but are accepted as conditions:
- Truthys:
Object
, Array
, non empty string, number other than 0, Date
- Falsys:
""
, 0
, null
, undefined
, NaN
!!
(“bang bang”) converts Truthy/Falsy to boolean “true” or “false”
Better console.log
- Original
console.log(error,loading,success,data);
- Variant 1:
console.log(
Error:${error},Loading:${loading},Success:${success},Data:${data});
- Variant 2:
console.log({error,loading,success,data});
- Grouping logs:
console.groupCollapsed
/ console.groupEnd
events
event.target
<– the thing that actually got clicked
event.currentTarget
<– the thing that fired the event listener, this is what you should use in most cases
Pointer events
isTrusted
is a parameter for determining if the event is clicked by the mouse or programmatically clicked
prevent from running
event.preventDefault();
event.preventStopPropagation();
Propagation (bubbling up) + Capture (trickle down)
- Note: I still don’t quite understand this, specifically the capture phase and reversing the order
- Capture phase, Target phase, Bubbling phase
- Capture Phase:
Document
-> <html>
-> <body>
-> <main>
- Target Phase:
<button>
- Bubbling Phase:
<main>
-> <body>
-> <html>
-> Document
addEventListener(type, listener, useCapture)
, e.g. addEventListener('click', functionCallback(), { capture: true})
to reverse (so this is the Capture down, instead of the Bubbling up)
Functional Programming via Filter Map Sort Reduce
- filter - loop over array and for each item, decide to keep or not. return
true
means keep it
- map - loop over array and returns new array of same length,
- sort - loop over array and returns new array of same length, return “1” if condition is true, and -1 if not
- reduce - loop over array and count
const totalValue = arrayName.reduce((total,arrayItem) => {
return total + arrayItem.doSomething;
},0);
Imperative Programming
- uses a sequence of statements to determine how to reach a certain goal
- these statements are to change the state of the program as each one is executed in turn
JAMstack - Javascript, APIs, Markup
- Javascript: Vue, React, Angular, Ember
- APIs: Contetnful, GraphQL, IMGIX
- Markup: Gatsby, Markdown, YAML, HTML
Adding to the DOM via JavaScript
document.getQuerySelector().insertAdjacentElement(position,element);
<!-- beforebegin -->
<p>
<!-- afterbegin -->
foo
<!-- beforeend -->
</p>
<!-- afterend -->
- Doing this allows use of DOM code manipulation on html_code_string (e.g. adding an Event Listener), which you wouldn’t be able to do with an html_code_string
document.createRange().createcontextualFragment(html_code_string)
Scope
Global Scope
- Global Scope is attached to Window
var
variables and functions are attached to the window object and globally scoped
let
and const
are globally scoped by not attached to the window object
Block Scope
let
and const
and block scoped
{
and }
are like gates
Function Scope
var
is function scoped
- Scope Lookup - it checks current scope and if not found, goes up a level
- Variable is Shadowed when a variable with the same name is created in a function. Not illegal but not a good idea.
Lexical Scoping
- arrow functions do not beind their own
this
, instead they inherit the one from the parent scope
this
is referrring to where it’s defined, not where it’s run
this
- in regular functions,
this
keyword represented the object that called the function, which could be the window, the document, a button or whatever
- Dan Abramov: in arrow functions,
this
keyword always represents the object that defined the arrow function. don’t use arrow functions if you need this
, for event listeners
says: “it’s like a hidden argument to your function. calls with dot, like obj.fn(), pass the part before the dot (obj) as this. calls without a dot, like fn(), don’t pass any this. if you didn’t pass any this, it’s set to a default (undefined in strict mode, window in loose mode)”
Hoisting
- before executing your code in the order you wrote it, javascript “pulls up” two types of declarations, so you can call them before they’re defined.
function functionName() {} //function declaration
var variableName; //variable declaration
to the top of the containing function (or file if you’re at top level). this lets you call a function declared this way even if it’s defined below.
However, function expressions are not hoisted up, nor are variables defined with let
const functionName = function() {} //function expression
let variableName; //let variable declaration
Closures
- Ability to access a parent scope data after it’s run and (it should be garbage collected)
- Dan Abramov: function variables are still accessible after function is run
says: “functions can read or write variables “outside” of them. this works not only with top level variables, but with local variables too (from nested functions). that’s called closures.”
Adding Event Listeners to multiple items
- One way (what I usually do):
buyButtons.forEach(button => {
button.addEventListeners('click', callbackFunction);
});
- Another way + the ability to unbind
function handleClick(button) {
button.addEventListeners('click', callbackFunction);
}
buyButtons.forEach(handleClick);
Headless
- Wordpress, Drupal, Shopify are now also Headless (previously not Headless)
- Head is the what is seen (website, mobile, shop, social media, wearable)
- Body is the data, the backend
The Main Thread
- Parses HTML, Builds the DOM, Parses CSS, Executes JavaScript, Responds to User Events
- try to leave main thread for UI updates + User Interaction
Web Workers
- Make it possible to run a script operation in a background thread separate from the main execution thread of a web app
- Cannot make changes to the DOM directly
- Service worker is specialized version of web worker
Arrow functions
- are anonymous functions (you don’t use the term function)
- implicit return - one line, no return, no curly brackets
- if you wanted to implicitly return an object, wrap in parenthesis/smooth bracket ();
To execute functions immediately, as soon as they are created
Don’t pollute the global object, simple way to isolate variables declarations
(function() {
/* */
})();
(function doSomething() {
/* */
})();
(() => {
/* */
})();
Async Await
- A concept of asynchronous programming, a specific way to write asynchronous promise based code.
- Example:
async function functionName() {
const res = await fetch("url");
console.log(res.json());
}
The console.log doesn’t run until after the await
is completed
Promises
What is the extent of your experience with Promises and/or their polyfills? What are the pros and cons of using Promises instead of callbacks?
- Async Await is cleaner to write and easier to deal with when there are lots of callbacks (and you get into nested callback hell)
JavaScript Functions are First Class Citizens
- functions are values, they can be stored as variables
.apply
and .call
- apply lets you invoke the function with arguments as an array;
- MDN - apply
- call requires the parameters be listed explicitly.
- MDN - call
- Example:
function theFunction(name, profession) {
console.log("My name is " + name + " and I am a " + profession +".");
}
theFunction("John", "fireman");
theFunction.apply(undefined, ["Susan", "school teacher"]);
theFunction.call(undefined, "Claude", "mathematician");
theFunction.call(undefined, ...["Matthew", "physicist"]); // used with the spread operator
function.prototype.bind
- Dan Abramov: a method that, when called, has its
this
keyword set to the provided value
this
is a hidden argument to your function. “bind” wraps a function with the this
you provide so that you don’t need to remember to pass the correct this
every time
- MDN
When would you use document.write()?
- sometimes working with third parties like Google Analytics, which have no control over the users brower’s dependencies (e.g. jQuery)
- Note:
document.write()
fires after a page is finished loading and may not even fire at all
What’s the difference between feature detection, feature inference, and using the UA string?
- Feature Detection: Checking if the feature exists, e.g.
if (navigator.geolocation) { /* do something */ }
- Feature Inference: Assuming the feature exists and using it
- UA String: navigator.userAgent outputs a string of data. this method can be easily spoofed
Explain how JSONP works and why it’s not really AJAX
- JSONP is sending JSON data without cross domain issues, e.g. requesting an external script from another domain:
Instead of
//alpha.com code
fetch('https://beta.com/file.json')
which would return a cross domain issue (CORS), you could do
<!--alpha.com code-->
<script src="https://beta.com/file.json"></script>
//https://beta.com/file.json
myFunction({
//object
})
where myFunction
is defined on alpha.com code.
Difference between document load event and document ready event?
- document load event: When the DOM has loaded, without waiting for the resouces to load, e.g.
document.addEventListener("DOMContentLoaded", () => { })
;
- document ready event: When the DOM and resources are loaded, ready to execute JavaScript code, e.g.
window.addEventListener('load', () => { }, false)
;
Why would you use something like the load event? Does this event have disadvantages? Do you know any alternatives, and why would you use those?
- load event fires at the end of the document loading process (DOM + resources) have finished loading.
- DOMContentLoaded event will fire after the DOM for the page has been constructed, but do not wait for other resources to finish loading. This is preferred in certain cases when you do not need the full page to be loaded before initializing.
Explain the same-origin policy with regards to Javascript
- security mechanism that restricts a resource that is loaded/accessed in one particular origin from another origin
- two origins are considered the same if their hostname, port, and protocol are the same
Why is it called a Ternary expression, what does the word “Ternary” indicate?
- Ternary operand accepts three parameters:
//conditional
if(conditional) { // one
truthy_block // two
} else {
falsy_block // three
}
//ternary expression
(conditional) ? truthy_block : falsy_block
what is "use strict";
? what are the advantages and disadvantages to using it?
"use strict";
instructs the browser to use the Strict mode, which is a reduced and safer feature set of JavaScript
- Advantages:
- eliminates some JavaScript silent errors by changing them to throw errors
- fixes mistakes that make it difficult for JavaScript engines to perform optimizations: strict mode code can sometimes be made to run faster than identical code that’s not strict mode
- prohibits some syntax likely to be defined in future versions of ECMAScript
- prevents, or throws errors, when relatively “unsafe” actions are taken (such as gaining access to the global object)
- disables features that are confusing or poorly thought out
- makes it easier to write “secure” JavaScript
Explain what a single page app is and how to make one SEO-friendly.
- A page/app/website that doesn’t require any more page loads after the first page view load (e.g. React, Angular, and Vue)
- To improve SEO, ensure there’s an XML sitemap, Views as URLs (via a router), Static Site Generation
What are some of the advantages/disadvantages of writing Javascript code in a language that compiles to Javascript?
Advantages:
- Types (via TypeScript) can improve stability and reduces errors in JavaScript
Disadvantages:
- Need something to transpile the code to JavaScript
- Lint, or a linter, is a static code analysis tool (e.g. eslint) used to flag programming errors, bugs, stylistic errors and suspicious constructs
What is an event loop?
- JavaScript’s runtime model, responsible for executing the code, collecting and processing events, and executing queued sub-tasks
- Dan Abramov: event loop is a set of rules for how the runtime (browser / Node) decides what code to run when it has finished running the current code. for example “okay we’ve exited all functions, so now, let’s run expired timeouts”. that includes code after “await” if the thing has resolved
- MDN
To Revisit
I’ve posted some questions I’ve seen online that I tried to look into but I still have trouble understanding. Sometimes with experience, things like this clear themselves up over time.
What are generators
- allow you to define an iterative algorithm by writing a single function whose execution is not continuous
- Generator functions are written using the function* syntax
- Dan Abramov: generators let your function return multiple values. not necessarily immediately — the caller decides when to ask for the next one. useful to describe operations where you can “ask for more”, like processing a long list or deciding each next step based on user input
- MDN
What is currying
- an advanced technique of working with functions
- a transformation of functions that translates a function from callable as
function(a, b, c)
into callable as functions(a)(b)(c)
- Dan Abramov: imagine functions only take one argument. how would we pass many? one way is to pass an object:
({ a, b, c }) => …
but we could also turn our function into a matryoshka of many functions where each takes one arg: (a) => (b) => (c) => …
that’s currying. not very useful in js.
- Example:
function curry(f) { // curry(f) does the currying transform
return function(a) {
return function(b) {
return f(a, b);
};
};
}
// usage
function sum(a, b) {
return a + b;
}
let curriedSum = curry(sum);
console.log( curriedSum(1)(2) ); // 3
What are monads?
- highly composable unit (a kind of building blocks of programming) in functional programming
- Dan Abramov: it’s an abstraction but a very generic one so hard to describe. i’d describe it as “wrapper for a value which lets you apply operations on that value, producing more such wrappers”. promise then(), if we skip minor pedantic distinctions, are an example of that.
When to use classes instead of factory functions
- factory function returns an object
- Dan Abramov: if you want people to extend your classes (to fill in some functionality) then it seems like it’s easier to do this with actual classes.
Use cases for WeakMap/WeakSet
- Dan Abramov: associate some information with an object i don’t own. like a memoization cache. weakmap is good for this because it doesn’t hold onto it, so i’m not causing a memory leak. the tradeoff is i can’t iterate over the list of objects for which i hold information.
TypeScript
if (typeof padding === "number") {
- Type Narrowing: the process of refining types to more specific types
-
- Implicit Types do not need to be declared. Examples can be private or local variables
-
- TC39 - Types //as Comments ECMAScript Proposal for TypeScript inside JavaScript
The State of JS
I always find the State of JS survey as one of the best ways to learn something new/cutting edge.
Here, I’ll list some items and a brief description / info on what it is - mostly for my own learning:
Language
Numeric Separators
- To improve readability, this feature enables underscores as separators in numeric literals.
- For example:
1000000000000
-> 1_000_000_000_000
1019436871.42
-> 1_019_436_871.42
- MDN
String.prototype.replaceAll()
- The
replaceAll()
method returns a new string with all matches of a pattern
replaced by a replacement
- Example:
const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
//
console.log(p.replaceAll('dog', 'monkey'));
// expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"
//
// global flag required when calling replaceAll with regex
const regex = /Dog/ig;
console.log(p.replaceAll(regex, 'ferret'));
// expected output: "The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?"
String.prototype.matchAll()
- The
matchAll()
method returns an iterator of all results matching a string against a regular expression, including capturing groups.
- Example:
const regexp = /t(e)(st(\d?))/g;
const str = 'test1test2';
//
const array = [...str.matchAll(regexp)];
//
console.log(array[0]);
// expected output: Array ["test1", "e", "st1", "1"]
//
console.log(array[1]);
// expected output: Array ["test2", "e", "st2", "2"]
Regexp Match Indices / String.prototype.match()
- The match() method retrieves the result of matching a string against a regular expression.
- Example:
const paragraph = 'The quick brown fox jumps over the lazy dog. It barked.';
const regex = /[A-Z]/g;
const found = paragraph.match(regex);
//
console.log(found);
// expected output: Array ["T", "I"]
Array.prototype.at()
- The at() method takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array.
- Example:
const array1 = [5, 12, 8, 130, 44];
let index = 2;
//
console.log(`Using an index of ${index} the item returned is ${array1.at(index)}`);
// expected output: "Using an index of 2 the item returned is 8"
//
index = -2;
//
console.log(`Using an index of ${index} item returned is ${array1.at(index)}`);
// expected output: "Using an index of -2 item returned is 130"
Array.findLast()
- The
findLast()
method iterates the array in reverse order and returns the value of the first element that satisfies the provided testing function. If no elements satisfy the testing function, undefined is returned.
- Example:
const array1 = [5, 12, 50, 130, 44];
const found = array1.findLast((element) => element > 45);
console.log(found);
// expected output: 130
Object.hasOwn()
- The
Object.hasOwn()
static method returns true
if the specified object has the indicated property as its own property. If the property is inherited, or does not exist, the method returns false
.
- Example:
const object1 = {
prop: 'exists'
};
console.log(Object.hasOwn(object1, 'prop')); // expected output: true
console.log(Object.hasOwn(object1, 'toString')); // expected output: false
console.log(Object.hasOwn(object1, 'undeclaredPropertyValue')); // expected output: false
Promise.allSettled()
- Takes an array of promises and returns a single Promise. The returned promise fulfills when all the input promises are settled and returns with an array that describes each outcome of each input promise (e.g. “fulfilled” “rejected”)
- MDN
Promise.any()
- The Promise.any() method takes an iterable of promises as input and returns a single Promise. This returned promise fulfills when any of the input’s promises fulfills, with this first fulfillment value. It rejects when all of the input’s promises reject (including when an empty iterable is passed), with an AggregateError containing an array of rejection reasons.
- Example:
const promise1 = Promise.reject(0);
const promise2 = new Promise((resolve) => setTimeout(resolve, 100, 'quick'));
const promise3 = new Promise((resolve) => setTimeout(resolve, 500, 'slow'));
//
const promises = [promise1, promise2, promise3];
//
Promise.any(promises).then((value) => console.log(value));
//
// expected output: "quick"
Top Level await()
- Top-level await enables developers to use the await keyword outside of async functions. It acts like a big async function causing other modules who import them to wait before they start evaluating their body.
- Old way:
(async function() {
await Promise.resolve(console.log('🎉'));
// → 🎉
}());
await Promise.resolve(console.log('🎉'));
// → 🎉
Dynamic Import
// say.js
export function hi() {
alert(`Hello`);
}
export function bye() {
alert(`Bye`);
}
// another file.js
let {hi, bye} = await import('./say.js');
hi();
bye();
Temporal
Logical OR ||
e.g. expr1 || expr2
- If
expr1
can be converted to true
, returns expr1
; else, returns expr2
.
false
is null
, NaN
, 0
, empty string ""
, ''
, or undefined
- MDN
Logical AND &&
e.g. expr1 && expr2
- If value can be converted to true, value is truthy. If value can be converted to false, value is falsy.
- Items that can be converted to
false
is null
, NaN
, 0
, empty string ""
, ''
, or undefined
- In React,
(true && 'Hello World')
evaluates to Hello World
and (false && 'Hello World')
evaluates to false
- MDN
Nullish Coalescing
Operator ??
- The nullish coalescing
??
operator is a logical operator that returns its right-hand side operand when its left-hand side operand is null
or undefined
, and otherwise returns its left-hand side operand.
- For example:
const foo = null ?? 'default string';
console.log(foo);
// expected output: "default string"
const baz = 0 ?? 42;
console.log(baz);
// expected output: 0
Assignment ??=
- The nullish coalescing assignment
x ??= y
operator only assigns if x is nullish
(null
or undefined
).
- For example:
const a = { duration: 50 };
a.duration ??= 10;
console.log(a.duration);
// expected output: 50
a.speed ??= 25;
console.log(a.speed);
// expected output: 25
Logical Assignment
- The logical OR assignment
(x ||= y)
operator only assigns if x is falsy
- Example:
const a = { duration: 50, title: '' };
//
a.duration ||= 10;
console.log(a.duration);
// expected output: 50
//
a.title ||= 'title is empty.';
console.log(a.title);
// expected output: "title is empty"
Proxies
- Create a proxy for another object that can intercept, redefine fundamental operations for that object. Generally used to log property access, validate, format, or sanitize inputs, etc.
- MDN
Private Fields
- ES2022 allows private fields for a class - you can prefix the field name with #, e.g.
class ClassWithPrivate {
#privateField;
#privateFieldWithInitializer = 42;
#privateMethod() {
// …
}
static #privateStaticField;
static #privateStaticFieldWithInitializer = 42;
static #privateStaticMethod() {
// …
}
}
Error.prototype.cause
- The cause data property of an Error instance indicates the specific original cause of the error. It is used when catching and re-throwing an error with a more-specific or useful error message in order to still have access to the original error.
- Example:
try {
connectToDatabase();
} catch (err) {
throw new Error('Connecting to database failed.', { cause: err });
}
Browser APIs
Service Workers
- Service worker is specialized version of web worker.
- Service workers act as proxy servers that sit between web applications, the browser, and the network (when available).
- Service workers are intended to enable the creation of effective offline experiences, intercept network requests and take appropriate action based on whether the network is available, and update assets residing on the server.
- Service workers will also allow access to push notifications and background sync APIs.
- MDN
Intl
- A Global Object namespace for the ECMAScript Internationalization API, which provides language sensitive string comparison, number formatting, and date and time formatting
- MDN
WebGL
- Web Graphics Library (WebGL) is a JavaScript API for rendering interactive 2D and 3D graphics within any compatible web browser without the use of plug-ins.
- MDN
Web Animations
- Using .animate as an alternative to CSS animations
- MDN
WebRTC
- Enables websites to optinally capture and stream video and audio
- MDN
Web Speech API
- For speech recognition or Speech synthesis (aka text-to-speech, or tts)
- MDN
WebSocket
- open a two-way interactive communication session between the user’s browser and a server (send messages to a server and receive event-driven responses)
- MDN
Custom Elements
- customElements (read-only property) of
window
interface that returns a reference to the CustomElementRegistry
object, which can be used to register new custom elements and get information about previously registered custom elements.
- The basis for Web Components
- MDN
- GitHub - Web Component Examples
Shadow DOM
-
“An important aspect of web components is encapsulation — being able to keep the markup structure, style, and behavior hidden and separate from other code on the page so that different parts do not clash, and the code can be kept nice and clean. The Shadow DOM API is a key part of this, providing a way to attach a hidden separated DOM to an element.”
- MDN
Page Visibility API
- provides events to know when a document becomes visible or hidden
- useful for saving resources and improving performance by letting a page avoid performing unnecessary tasks when the document isn’t visible.
document.visibilityState
: A string indicating the document’s current visibility state. Possible values are:
visible
: The page content may be at least partially visible. In practice this means that the page is the foreground tab of a non-minimized window.
hidden
: The page’s content is not visible to the user, either due to the document’s tab being in the background or part of a window that is minimized, or because the device’s screen is off.
- Example of listener for visibility change:
document.addEventListener("visibilitychange", () => {
if (document.hidden) {
audio.pause();
} else {
audio.play();
}
});
- MDN
Broadcast Channel API
- allows basic communication between browsing contexts (that is, windows, tabs, frames, or iframes) and workers on the same origin
- MDN
Geolocation API
- allows the user to provide their location to web applications if they so desire
- MDN
File System Access API
- allows interaction with files on a user’s local device, or on a user-accessible network file system. Core functionality of this API includes reading files, writing or saving files, and access to directory structure.
- MDN
Web Share API
- provides a mechanism for sharing text, links, files, and other content to an arbitrary share target selected by the user
- MDN
WebXR Device API
- Find compatible VR or AR output devices, Render a 3D scene to the device at an appropriate frame rate, (Optionally) mirror the output to a 2D display, Create vectors representing the movements of input controls
- MDN
Other Features
Progressive Web Apps
- Progressive Web Apps (PWAs) are web apps that use service workers, manifests, and other web-platform features in combination with progressive enhancement to give users an experience on par with native apps.
- MDN
WebAssembly (WASM)
- WebAssembly is a new type of code that can be run in modern web browsers — it is a low-level assembly-like language with a compact binary format that runs with near-native performance and provides languages such as C/C++, C# and Rust with a compilation target so that they can run on the web. It is also designed to run alongside JavaScript, allowing both to work together.
- MDN
Front end Frameworks (2022 version)
Rendering Frameworks
Testing
Mobile & Desktop
Date Management
Data Visualization
Graphics & Animations
Data Fetching
Back-end Frameworks
Utilities
JavaScript Runtimes
JavaScript Edge/Serverless Runtimes
JavaScript Flavors
Non-JavaScript Languages
Which sites/courses/etc. do you consult?
Video Creators
Podcasts
OLD STUFF: Vanilla JS IE11 Friendly AJAX Request
Vanilla JS IE11 Friendly AJAX Requestfunction jsonp(uri) {
return new Promise(function(resolve, reject) {
var id = '_' + Math.round(10000 * Math.random());
var callbackName = 'jsonp_callback_' + id;
window[callbackName] = function(data) {
delete window[callbackName];
var ele = document.getElementById(id);
ele.parentNode.removeChild(ele);
resolve(data);
}
var src = uri + '&callback=' + callbackName;
var script = document.createElement('script');
script.src = src;
script.id = id;
script.addEventListener('error', reject);
(document.getElementsByTagName('head')[0] || document.body || document.documentElement).appendChild(script)
});
}
if (navigator.userAgent.toLowerCase().indexOf('msie') > -1 && window.XDomainRequest) {
// Use Microsoft XDR
var xdr = new XDomainRequest();
xdr.open("get", url);
xdr.onload = function() {
// XDomainRequest doesn't provide responseXml, so if you need it:
var dom = new ActiveXObject("Microsoft.XMLDOM");
dom.async = false;
dom.loadXML(xdr.responseText["data"][0]);
};
xdr.send();
} else {
jsonp(url).then(function(data){
temp_get_symbol_payload = data["data"][0];
/*if there are more than 1 result(s)*/
if (temp_get_symbol_payload) {
if (temp_get_symbol_payload.length > 0) {
get_holding_payload.classList.remove("display:none");
get_holding_payload.innerHTML = "";
/*iterate through*/
for(let i=0;i<temp_get_symbol_payload.length;i++) {
get_holding_payload.insertAdjacentHTML('beforeend', self.render_autocomplete_result(query,i,input_id,autocomplete_id,temp_get_symbol_payload[i]));
if (i === results_max_results) {
break;
}
}
}
}
});
}