Forum Moderators: open
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Reset textarea</title>
</head>
<body>
<textarea id="ta">
<p>Hello</p>
</textarea>
<input type="button" value="Reset" onclick="reset();">
<script>
function reset() {
var ta = document.getElementById('ta');
if (!ta.value || ta.value != ta.defaultValue && confirm('Are you sure?')) {
ta.value = ta.defaultValue;
}
}
</script>
</body>
</html>
Expected '!==' and instead saw '!='.
The '&&' subexpression should be wrapped in parens.
if (!ta.value || (ta.value != ta.defaultValue && confirm('Are you sure?')))
Since the textarea value and default value are always of the type string
Why should I add parenthesis when && has a higher precedence than ||?