None value is not coverted to null in JavaScript.
See original GitHub issueI don’t know if this is a bug but I have code like this (that use jQuery Terminal library):
from browser import window, alert
def interpreter(command, term):
term.echo(">>> " + command)
window.jQuery("body").terminal(interpreter)
and I have exception in JavaScript because None value returned by interpreter is a cycle that can’t be used in JSON.stringify because In jQuery Terminal the value returned by the function is processed and echoed in terminal (It can be a string or a promise). Is there a way to convert None
to null or undefined to be used in JavaScript or return undefined/null from javascript?
I’ve fixed the issue by wrapping terminal function invocation and wrap interpreter with function that don’t return anything, but it would be nice if Brython convert None to null in python functions.
I’m using stable version from github.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
JavaScript Null does not convert to None - Stack Overflow
Generally, "null" items would be missing entirely, alternatively, they would have an empty value associated with them.
Read more >null - JavaScript - MDN Web Docs - Mozilla
The null value represents the intentional absence of any object value. It is one of JavaScript's primitive values and is treated as falsy...
Read more >How null is converted to Number in JavaScript? - Tutorialspoint
The Number() method in JavaScript is used to convert a value into a number. If the value is not convertible, then it will...
Read more >Understanding Null Versus the Empty String
For example, any code inside the following conditional block will not execute because the value of varA (null) does not equals the value...
Read more >DoubleConverter cannot convert from (null) - UiPath Forum
No it won't. Logically when field is empty the robot get the text as null, that's not a value to a variable, it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In the commit referenced above I have added 2 new constants in built-in module javascript, called
NULL
andUNDEFINED
, set to Javascript valuesnull
andundefined
. They can be returned by a Brython function used by a Javascript library that handles these values.I tried this code in a page with the Terminal library :
I don’t know if the program does what is expected, but at least it doesn’t crash 😉
Does this help ?
As Jonathan said, it’s not possible for a function to know if it’s called from Brython or Javascript. And anyway, there must be a way to return either
null
orundefined
(I saw that jQuery Terminal doesn’t handle these values the same way).Can the issue be closed ?