Show a variable with spaces

0
var a = '
          \  ^___^
           \ (ooo)\_______
             (___)\       )\/\
                  ||----w |
                  ||     ||
'

          document.write(a);

How do they show that variable as it really is, and not linearly?

    
asked by Eduardo Sebastian 14.06.2017 в 03:00
source

2 answers

2

String.raw () is a postprocessed tag function for text string templates, available in ECMAScript 2015 (ES6). It is used to obtain the raw string ( raw ) of the template, without interpreting it. It is analogous to a string verbatim in JavaScript. See compatibility .

var literal = String.raw'Tex\to
No \ "interpretado" \ .
Incluso \n no es un salto de línea';


Also, when it is printed in the browser, it would also be interpreted, so it can be printed on a <pre> tag.


var a = String.raw'
          \  ^___^
           \ (ooo)\_______
              (___)\       )\/\
                   ||----w |
                   ||     ||
';

document.write('<pre>' + a + '</pre>');
    
answered by 14.06.2017 в 05:19
0

You will have to concatenate the lines with the operator + and give the blank spaces you need, when you declare the variable.

var a = 
        '\  ^___^' +
        ' \ (ooo)\_______' +
        '   (___)\       )\/\' +
        '        ||----w |' +
        '        ||     ||';
    
answered by 14.06.2017 в 03:18