1

I am new to JavaScript and this is my first question on Stackoverflow, please let me know if I missed something which should be included in the question.

Question 1: Can anyone explain why sometimes the console output sequence does not match with the sequence in which they are called (myFunction(); and messageLogger();).

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test Page</title>
</head>
<body>
    <script>
        let myFunction = function messageLogger() {
            console.log('Message Logged');
        }
        myFunction();     //Should output message in console
        messageLogger();  //Should generate error in console
    </script>
</body>
</html>

This is Basic Function Expression code as shown above and in the image Original Code Image.

This code should show error in console after running myFunction(); as in image Console Output Image 1, but sometimes show's error before running myFunction(); as in image Console Output Image 2.

AtlasUser5
  • 81
  • 6
  • 6
    It's probably just a `console` quirk; it doesn't do that here. – Pointy Oct 06 '20 at 20:04
  • 1
    Which browser's console is that, specifically? I'd recommend to report it as a bug. – Bergi Oct 06 '20 at 20:07
  • 2
    Congratulations on a well-asked first question! The only suggestion would be not to post images of code or output. Copy/paste the relevant section into a code block instead. (And there is certainly no reason to duplicated the useful code you already posted with an image!) As to an answer, Pointy's comment is probably all you need, and Bergi's suggestion is useful too. – Scott Sauyet Oct 06 '20 at 20:17
  • Please add your browser and operating system information. Judging by the UI in the pictures, is it MS Edge on Windows 10? – shreyasm-dev Oct 06 '20 at 21:42
  • Apologies to all, I read your comments the first day but at that time I couldn't find perfect reason and solution to the problem. Till day I don't know what was the reason for bug but it got solved. – AtlasUser5 May 08 '22 at 17:26
  • @Pointy Absolutely Correct, it was console quirk and only for Edge that too years ago. – AtlasUser5 May 08 '22 at 17:26
  • @Bergi I haven't seen the bug since the transition of Edge to Chromium hence didn't reported it. – AtlasUser5 May 08 '22 at 17:26
  • @shreyasm-dev Sorry for year's late reply and good observational skills, it was MS -Edge for Windows 10 and the error was never seen again after my Edge Browser got Chromium Update. – AtlasUser5 May 08 '22 at 17:28
  • 1
    Finally @ScottSauyet Thankyou for the advice, I am following it from the day I read it and this have helped me a lot. Have a Happy Year✌ – AtlasUser5 May 08 '22 at 17:29

1 Answers1

0

I haven't seen the problem after I updated the MS Edge Browser to Chromium version. I have no reason and solution to actual cause but issue cannot be seen anymore.

AtlasUser5
  • 81
  • 6