0

I found this example on the internet to understand cross realms and Symbols, however, I don't get the output the article states (both print false), am I replicating the example wrong? I want to try it because I want to learn about Symbols and cross kingdoms.

<body>
  <iframe srcdoc="<script>var sharedSymbol = Symbol.for('Shared symbol');</script>"></iframe>
  <script>
    const iframe = document.querySelector("iframe");
    const iframeWindow = iframe.contentWindow;

    // Will print false!
    console.log(iframeWindow.Symbol === Symbol);

    // But will print true!
    console.log(iframeWindow.sharedSymbol === Symbol.for("Shared symbol"));
  </script>
</body>
  • 1
    Does this answer your question? [Symbol.for(string) in ECMAScript 6](https://stackoverflow.com/questions/30984858/symbol-forstring-in-ecmascript-6) – Rodrigo Rodrigues Mar 23 '22 at 19:19
  • Hi, not quite, I understand that Symbols cross realms but I have not been able to check it with iframes as many articles point out (I'm a bit picky) and I want to check it myself –  Mar 23 '22 at 19:23

0 Answers0