+ 1
Compatibility issues in Code Playground (for JavaScript)
Here's my JavaScript code: const x = 1; const y = 2; const z = 3; console.log(x,y,z); If I run this in my browser console, or even anywhere except code playground, the output is: 1 2 3 However, if I run this in Sololearn's Code Playground, it only returns the first constant, which in this case is 1. I even tried replacing console.log() with alert(), but still no luck. I want to address the attention of everyone regarding this matter.
3 Respostas
+ 2
It should work with: console.log(x+' '+y+' '+z);
The problem comes from the fact that implementation of 'console' object in android webview isn't as complete as browsers version (there's no standard specification, each implementation could do whatever improvment they want, standard only finally come from each copying others good improvements; also, android wasn't targeted as deveopment tool, so console in mobile browsers almost doesn't exist) or even as code playground bypassing implementation (which suffer from some limitations too)...
+ 1
document.write() output in document console.log() output outside the document.
Both are not of same JS part: first is related to DOM api, while second is related to browser vendors api.
It seems that webview implementation of console.log() handle only one argument, while most of other implementation handle 'argument' array-like object (or '...' operator of rest of argument) to handle an infinite number of arguments to output.
So do document.write(), but usually console.log() join each argument with one space, while document.write() concatenate them without spaces.
If your goal is to have such behaviour in console, rather do:
console.log(''+a+b+c);
The empty string will force cast to string to output all three values without space between them...
0
It works using document.write(), however, there's no space between the three constants.