How can I put simple quotes inside simple quotes in javaScript

0

My problem is this: This is the code that I need to pass to an X component:

'date = '24 / 4/2017' ';

The problem is that the simple quotes of the date do not read them to me normally, but it complies with a strange numbering like (& # 39) or something like that. please help-me !!!

    
asked by Oscar Leyva 06.11.2017 в 19:28
source

3 answers

2

As you wrote @Yikarus in the comment, you have to escape the character ' using \ as follows:

var mi_variable = 'Un \'texto\' cualquiera';

Greetings.

    
answered by 06.11.2017 в 19:54
0
onclick="menorDeEdad('24/4/2017')";

function menorDeEdad(fecha){
console.log(fecha);
}

something like that?

you want the date

var f = new Date();
fecha= f.getFullYear();

if not then send the error that appears to you

    
answered by 06.11.2017 в 19:43
0

"Escape" is the term used, meaning that being special characters, you must "escape" to take them as they are LITERAL and you are not using it as its special functionality, in this case the functionality of '' is to enclose a text, but since you do not want it for that, but literally the single quotes, the ESCAPES.

var a = "\'Hola\'";
console.log(a)
    
answered by 06.11.2017 в 23:08