Copyright © tutorialspoint.com
This method returns a debug-oriented version of the string i.e. wrapped in single or double quotes, with backslashes and quotes escaped.
string.inspect([useDoubleQuotes = false]); |
<html>
<head>
<title>Prototype examples</title>
<script type="text/javascript"
src="/javascript/prototype.js">
</script>
<script>
function showResult(){
var str = 'I\'m so happy.';
alert( "Check without inspect :" + str );
alert( "First Check :" + str.inspect() );
alert( "Second Check :" + str.inspect( true ) );
}
</script>
</head>
<body>
<p>Click the button to see the result.</p>
<br />
<br />
<input type="button" value="Result" onclick="showResult();"/>
</body>
</html>
|
This returns the following value in actual but it will return different values in alert dialog or the console.
Check without inspect: I'm so happy. First Check : '\'I\\\'m so happy.\'' Second Check : '"I'm so happy."' |
To understand it in better way you can Try it yourself.
Copyright © tutorialspoint.com