How do I setup a piece of code to write to an Excel file?

Hi, this is my first project. I want to create a script that will grab & write a selected (highlighted) word in Safari to an Excel file when I 2-finger-tap on my trackpad.

I decided the best option would be to use the ' Run Real Javascript ' functionality in BTT to do this. Can someone confirm that this is the way to go as opposed to using ' Apple Javascript for Automation ', for example?

Also, what would be the pseudocode / skeleton code on doing this? I can find JS code snippets on grabbing text from pages but not sure how to correctly integrate into BTT.

Am I supposed to write something like

(async () => {
const word = functionToGrabText();
functionToWriteToExcel(word);
})();

in the box in Action Configuration?

Thanks,