From 63be16858d65001a64b55ee0d831cb5eeee2284b Mon Sep 17 00:00:00 2001 From: Akash Prajapati Date: Tue, 20 Feb 2024 12:27:07 +0530 Subject: [PATCH 1/3] "use strict"; --- 101_use_strict/index.html | 11 +++++++++++ 101_use_strict/script.js | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 101_use_strict/index.html create mode 100644 101_use_strict/script.js diff --git a/101_use_strict/index.html b/101_use_strict/index.html new file mode 100644 index 0000000..35d66da --- /dev/null +++ b/101_use_strict/index.html @@ -0,0 +1,11 @@ + + + + + + use strict + + + + + diff --git a/101_use_strict/script.js b/101_use_strict/script.js new file mode 100644 index 0000000..da1f749 --- /dev/null +++ b/101_use_strict/script.js @@ -0,0 +1,26 @@ +"use strict"; +let a = 45; +console.log(a); + +// 1. demo1 of restriction after using "use strict" +d = 28; // not allowed because strict mode is on. +// Uncaught ReferenceError: d is not defined + + +// 2. demo2 of restriction after using "use strict" +console.log(this); +function tryThis(num) { + console.log(num); + console.log(this); // undefined. bcz in strict mode this can't be used inside function. +} +tryThis(5); +let fun = () => { + console.log(this); // window object +}; +fun(); + + +/** + * Note: + * react uses strict mode by default. + */ \ No newline at end of file From 060eb34d784b3b990c1349ebff81f64fc1587e77 Mon Sep 17 00:00:00 2001 From: Akash Prajapati Date: Tue, 20 Feb 2024 18:33:40 +0530 Subject: [PATCH 2/3] module as .mjs --- 102_module.mjs/module1.mjs | 11 +++++++++++ 102_module.mjs/package.json | 12 ++++++++++++ 102_module.mjs/script.mjs | 2 ++ 3 files changed, 25 insertions(+) create mode 100644 102_module.mjs/module1.mjs create mode 100644 102_module.mjs/package.json create mode 100644 102_module.mjs/script.mjs diff --git a/102_module.mjs/module1.mjs b/102_module.mjs/module1.mjs new file mode 100644 index 0000000..2f1d21b --- /dev/null +++ b/102_module.mjs/module1.mjs @@ -0,0 +1,11 @@ +const a = "Akash"; +const b = "akki"; +const c = "Shruti"; +const d = "zingur"; +const e = "Disha"; + +export default b; +export {a}; +export {c}; +export {d}; +export {e}; \ No newline at end of file diff --git a/102_module.mjs/package.json b/102_module.mjs/package.json new file mode 100644 index 0000000..77c9e3f --- /dev/null +++ b/102_module.mjs/package.json @@ -0,0 +1,12 @@ +{ + "name": "102_module.mjs", + "version": "1.0.0", + "description": "", + "main": "script.mjs", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/102_module.mjs/script.mjs b/102_module.mjs/script.mjs new file mode 100644 index 0000000..3cb5b5c --- /dev/null +++ b/102_module.mjs/script.mjs @@ -0,0 +1,2 @@ +import name from "./module1.mjs"; +console.log(name); \ No newline at end of file From ea205e578f257f276e83d3ae732c27f9d1c7e28b Mon Sep 17 00:00:00 2001 From: Akash Prajapati Date: Tue, 20 Feb 2024 18:35:40 +0530 Subject: [PATCH 3/3] module as .mjs --- 102_module.mjs/script.mjs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/102_module.mjs/script.mjs b/102_module.mjs/script.mjs index 3cb5b5c..b760543 100644 --- a/102_module.mjs/script.mjs +++ b/102_module.mjs/script.mjs @@ -1,2 +1,4 @@ -import name from "./module1.mjs"; -console.log(name); \ No newline at end of file +import name, {a, c} from "./module1.mjs"; +console.log(name); +console.log(a); +console.log(c); \ No newline at end of file