Call Site

Memosha Sinha
2 min readSep 16, 2019

--

This is the part 2 of the series on this keyword in Javascript.
Call-Site :
location where a function is called( not where it’s declared). Finding call site in plain JS code is simple but certain coding pattern can hide the true call-site.
For understanding this, we need to find the call-site before the currently executing function.

function findCallSite() {//call-stack is : findCallSite//our call-site is in global scopeconsole.log("Inside findCallSite");getToCallSite();}function getToCallSite() {//call-stack is findCallSite-> getToCallSite//so our callSite is findCallSiteconsole.log("Inside getToCallSite");getToSecondCallSite();}function getToSecondCallSite() {//call-stack is findCallSite-> getToCallSite->getToSecondCallSite//so our callSite is getToCallSiteconsole.log("Inside getToSecondCallSite");}findCallSite(); // call-site for findCallSite

Debugger in visual studio code will show call stack as below

--

--

Memosha Sinha

Software Engineer, Fitness lover, Traveller, wanderlust, optimistic