Why Javascript functions behave differently on Chrome 77.0.3865.120 and Safari 13.0.2?

Viewed 116

I noticed that functions behave differently on Safari and Chrome, is there any reason?

I don't need a solution, I just would understand why this happens and if it is a bug or whatelse. Here's how you can reproduce it. You'll see different values in Chrome's console and Safari's console.

    const foo = 10;
    {

        const foo = 50;

        function logFoo1(){
            console.log(foo)
        }

        const logFoo2 = function(){
            console.log(foo)
        }

        logFoo1();
        logFoo2();

    }

On safari logFoo1() will prompt 10, on Chrome 50.

1 Answers

Yes It does!

Same piece of Javascript code behaves differently in different browsers. Consider the following piece if code:

<script>

alert('\v supported ' + (String.fromCharCode(11)== '\v'));

</script>

Output:

IE: false

FF: true

Opera: true

Safari: true

The reason behind this is every browser has its own rendering engine.These are examples of browser engines. These engines are nothing but different adaptations of open Web standards

Related