JS working when used normally but not in wordpress

Solved.

The problem was that mojs has to be included between the <body></body> tags, and the wp_enqueue_script() function that enqueued mojs needed an empty string as argument just before the ‘true’ parameter (I forgot to specify that there was no required version number of that script).

So, changing

wp_enqueue_script('mojs', 'https://cdn.jsdelivr.net/mojs/latest/mo.min.js', array('jquery'), true);
wp_enqueue_script('favjs', $favbtnscript, array('jquery', 'mojs'), true);

to

wp_enqueue_script('mojs', 'https://cdn.jsdelivr.net/mojs/latest/mo.min.js', array('jquery'), '', true);
wp_enqueue_script('favjs', $favbtnscript, array('jquery', 'mojs'), '', true);

did the trick.