I think i got the answer,
according to https://www.w3.org/TR/html4/types.html#type-cdata
Although the STYLE and SCRIPT elements use CDATA for their data model,
for these elements, CDATA must be handled differently by user agents.
Markup and entities must be treated as raw text and passed to the
application as is. The first occurrence of the character sequence "< /"
(end-tag open delimiter) is treated as terminating the end of the
element's content. In valid documents, this would be the end tag for
the element.
the text of style and script elements use CDATA for their data model, and that text directly passed to application, ( javascript intrepreter in js, and layout engine in css(?)) and
the first occurrence of character sequence "< /" is treated as terminating the end of element (without space between < and / it was not working in answer, normal ?)
so when i we write :-
var string = "</script>";
the combination "< /" treated as end and that text content ( var string = " ) is passed to js intrepreter, and we know that string is not correclty ended ( " missing ), so that shows error, and then "); treated like text, and to solve this as the specification says combination of < / word as terminater, we can write like :-
var string = "<\/script>";
here html parser do not understand the javascript code so escape sequence not works, for html parser </ these are all 3 seperate charaters, and there are other a lot of variation to break "< \" token sequence,
ex:-
var str = "< /script>";
( did you notice space between < and /, i don't know it is allowrd in standard or not but it works )
var str = "<" + "/script>";
but there is also one thing to remember :-
var str = "< /scr" + "pt>" also works . ( forgot space, space for so. )
because according to :-
https://stackoverflow.com/a/236106/3810909
In practice browsers only end parsing a CDATA script block on an
actual close-tag.
thanks, and sorry for weak engilsh