Forum Discussion
Sharing variables between languages
Hi smpa01
It seems javascript is not an official supported language in the code cell of Fabric notebook. And it's a challenge to pass a variable between Pyspark code cell and JS code cell.
As an alternative, you may use Python to execute the JS code. Some python libraries provide the functionality to call Javascript from Python. This makes it easier to pass variables.
I create a sample as below by using js2py. Create a function in JS, then call this function by Python. We can pass python variables to the JS function and get the result into another python variable.
import js2py
get_pow = js2py.eval_js('function get_pow(a, b) {return Math.pow(a, b)}')
result = get_pow(10, 3)
print(result)
References:
Call Javascript from python - Stack Overflow
Best Regards,
Jing
If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!