I am new learner of JavaScript
. I saw the following code somewhere but can't understand why there is (
before async
and ()
after that? I know arrow functions in JavaScript but it seems this is a little different?
(async () => {
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.goto(
"http://www.tsetmc.com/Loader.aspx?ParTree=151311&i=46741025610365786#",
{ waitUntil: "networkidle2" }
);
await page.click(".menu2 .violet", { button: "left" });
await page.waitForSelector(".content .awesome", { timeout: 20000 });
const data = await page.evaluate(() => {
const trs = Array.from(document.querySelectorAll("#ClientTypeBody tr"));
const arr = [];
for (let i = 1; i < trs.length; i += 6) {
arr.push(trs[i].innerText
.replace(new RegExp("\t", "g"), ", ")
.replace(new RegExp("حجم", "g"), "")
.replace(/ \([^)]+\)/g, "")
.replace(",", ""));
arr.push('\n');
}
return arr.toString();
});
fs.writeFile("store.txt", data, err => {
if (err) throw err;
console.log("The file has been saved!");
});
await browser.close();
})();
What are the inputs/outputs of this function? ? Why the async
is inside of a ()
and there is also a blank ()
in front of it?