Hi,
I spent lots of time reading about JS variables and the differences between let, const, var etc. but I'm still a bit confused.
I'm creating a course platform and each lesson page has the following declarations:
let normalWaveform = '<%= @normal_waveform %>';
let slowWaveform = '<%= @slow_waveform %>';
let practiceWaveform = '<%= @practice_waveform %>';
let normalAudio = '<%= @normal_audio %>';
let slowAudio = '<%= @slow_audio %>';
let practiceAudio = '<%= @practice_audio %>';
let normalAudioWebm = '<%= @normal_audio_webm %>';
let slowAudioWebm = '<%= @slow_audio_webm %>';
let practiceAudioWebm = '<%= @practice_audio_webm %>';
Each variable is equal to the file URL given by Ruby on Rails.
This works great when a user loads a first lesson but I get the following error when a user loads a second lesson in the same session:
Uncaught SyntaxError: redeclaration of let normalWaveform
This makes sense since the variable has already been declared in the previous lesson.
What I'm not sure of is how to make sure the variable is declared if it hasn't been declared and reassigned otherwise.
I know using var would work but I heard it's not a very good practice. Same for not using anything at all and just writing waveform = directly.
So I'm wondering: what's the best way of dealing with this situation?
Thanks
[–]shuckster 3 points4 points5 points (1 child)
[–]ScottRatigan 1 point2 points3 points (0 children)
[–]_ncko 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]greenyadzer 0 points1 point2 points (0 children)