What I should know before coding javascript?

I usually create JavaScript code using ChatGPT, but sometimes I encounter issues that only Anki faces and my chatbot friend cannot grasp, and I always end up hitting a dead end. For example, my code does not run, and a nice guy on a forum said that I should not declare variables using “var” and wrap the code in an IIFE. Finally, after adding those two tips, the code ran smoothly, and from then on, I always included those prompts (of course I don’t know why it helps).
So, can you guys tell me some JavaScript tips that you often apply to your code?

Maybe it is time to pickup some basic programming knowledge the old way (book, tutorial, video, programming exercise)?


You are right, I’ll try but I think not now. I only have enough time in a day to read English books and make flashcards, and then go to work, you know, working 8 hours and changing shifts every week. I have also tried to learn basic coding knowledge couple months ago but failed, it seems that my time budget only allows me to do one thing.

+1 on learning programming fundamentals first.

Once you got a basic understanding of CS, the best way to learn a new programming language is to take on a challenge and start coding. Anki’s card templates are the perfect playground for that.

ChatGPT can be a useful tutor if you have specific questions along the way (not about Anki, but general JavaScript), but I wouldn’t trust it to create anything bigger than very simple functions.

I know it’s tempting to anthropomorphise that bot, but it doesn’t understand what you want. It just gives you the most likely sequence of words for the promt it’s provided with. Once you understood this limitation, it can be a very helpful tool to save some time.


Are you using GPT 4 or 3.5? When something doesn’t work specifically on Anki, I ask cgpt4 “This Javascript doesn’t work on Anki, can you fix it?” and then it does some crazy stuff involving Anki hooks on the javascript, and suddenly it works.

Of course, GPT3.5 doesn’t have that capability

It does, but your prompt need to be more speciffic than gpt4, and it also take much more attemps I guess. I use web inspector and some little debug tricks on youtube and then tell cgpt what is going on. Some time it works, some time it doesn’t.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.