我是JavaScript新手,想通過JSLint進行驗證。 我應該在哪裏放置「嚴格使用」以便在全球範圍內使用並驗證?如何在JSLint中全局設置'use strict'
這使我的錯誤「意外表達的意見書‘使用嚴格的’。」:
"use strict";
console.log('doing js in head-section');
function helloWorld() {
console.log('called function helloWorld()');
alert('Hello World from a JS function showing an alert!');
}
function helloMyNumber() {
console.log('called function helloMyNumber()');
var max = 42;
var yourLuckyNumber = prompt('Enter your lucky number (between 1 and '+ max +')');
var myLuckyNumber = Math.floor(Math.random()*(max+1));
var paragraph = document.getElementById('luckynumber');
paragraph.innerHTML = paragraph.innerHTML + ' Your lucky number is: ' + yourLuckyNumber + '. Mine is: ' + myLuckyNumber + '. They ' + (yourLuckyNumber == myLuckyNumber ? 'DID ' : 'did NOT ') + 'match!';
}
console.log('doing JS in body-section');
document.writeln('<p class="green">Hello World from JS within a body-section in HTML!</p>');
''使用嚴格的「;'在文件的開頭是完全有效的。 –