forked from uciharis/materi_masEko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path49_strictmode.js
executable file
·25 lines (24 loc) · 1.05 KB
/
49_strictmode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* --- strict Mode ---
* saat kita menjalankan kode program Javascript, secara default program
-kita berjalan dalam mode tidak strict (sloopy mode).
pada ECMAScript 5, diperkenalkan mode strict dimana ketika mode ini dijalankan,
maka akan mengubah beberapa cara kerja JS seperti :
- merubah beberapa JS error dari yang tadinya silent error menjadi throw error (terlihat)
- memperbaiki beberapa kesalahan engine JS utk dioptimasi
- menolak/blocked beberapa kode perintah yang sudah usang/tidak direkomen di ECMAscript
*/
//cara menyalakan strict mode
// tambahkan 'use strict' pada baris awal file JS atau di awal function
// -maka strict mode akan aktif di function tsb.
// penggunaan use strict diapit tanda petik 1
//contoh:
function useStrictMode(){
//'use strict' //---> jika ini diaktifkan dg apus komen, maka code with akan error
const person = {
firstName: "eko"
};
with (person) { //with adalah kode obselete
console.log(firstName);
}
};
useStrictMode() // output : SyntaxError: Strict mode code may not include a with statement