Skip to content

Instantly share code, notes, and snippets.

Last active October 18, 2023 01:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
<!DOCTYPE html>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Getter in Vanilla JS</title>
let rate = undefined;
const get_usd2inr = async () =>
return fetch("")
.then(response => response.json())
.then(response =>
return response['rates']['INR'];
document.addEventListener("DOMContentLoaded", async () =>
rate = await get_usd2inr();
let obj =
usd2inr1: rate,
get usd2inr2()
return rate;
Open Console but right clicking on the page and click Inspect Element.
<button onclick="console.log(obj.usd2inr1);">click 1</button>
<button onclick="console.log(obj.usd2inr2);">click 2</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment