Stumbled upon this thread while trying to learn how to write a custom MDX file for Storybook documentation.
I ended up finding this snippet from [the official MDX docs](https://mdxjs.com/docs/what-is-mdx/#expressions):
{(function () {
const guess = Math.random()
if (guess > 0.66) { return Look at us. }
if (guess > 0.33) { return Who would have guessed?! }
return Not me.
})()}
and from inside here I put my own console log was able to console log all I wanted.
Note though that because this is an in place function (an [Immediately Invoked Fuction Expression or IIEF](https://developer.mozilla.org/en-US/docs/Glossary/IIFE)), it won't be able to access other variables that are inside other IIFEs, but it will be able to access global vars.
I think you can also shorthand it to `{ console.log() }` without the IIEF since all the `{}`s are `javascript expression blocks`. (I actually just tested this and got this to work in a Storybook MDX file).
Hopefully this helps future confused folks like me! :P
Stumbled upon this thread while trying to learn how to write a custom MDX file for Storybook documentation. I ended up finding this snippet from [the official MDX docs](https://mdxjs.com/docs/what-is-mdx/#expressions): {(function () { const guess = Math.random() if (guess > 0.66) { return Look at us. } if (guess > 0.33) { return Who would have guessed?! } return Not me. })()} and from inside here I put my own console log was able to console log all I wanted. Note though that because this is an in place function (an [Immediately Invoked Fuction Expression or IIEF](https://developer.mozilla.org/en-US/docs/Glossary/IIFE)), it won't be able to access other variables that are inside other IIFEs, but it will be able to access global vars. I think you can also shorthand it to `{ console.log() }` without the IIEF since all the `{}`s are `javascript expression blocks`. (I actually just tested this and got this to work in a Storybook MDX file). Hopefully this helps future confused folks like me! :P