Javascript
/
Fundamentals
- 1 Fundamentals 11
-
Hello World S
-
Code structure S
-
Use strict S
-
Variables S
-
Data types S
-
Type conversions S
-
Maths S
-
Comparitions S
-
Conditional S
-
Loops S
-
Functions S
- 2 Testing 2
-
Mocha S
-
Nested describe S
- 3 Objects 4
-
Basics S
-
Reference S
-
Methods S
-
Constructor S
- 4 Types 5
-
Primitives S
-
Numbers S
-
Strings S
-
Arrays S
-
Json S
- 5 Classes 3
-
Constructor S
-
Binding S
-
Inheritance S
S
R
Q
Javascript Fundamentals Use Strict
Modern modifications, off by default Classes and modules, strict enabled by default "use strict"; let a = 1; try { b = 2 } catch (err) { // err.message, b not defined }StrictExceptions
Strict
To keep the old code working, modern modifications are off by default.
/**
* Modern modifications are off by default,
* to keep the old code working
*
* When 'use script' it is located at the top of a script,
* the whole script works the “modern” way
* starting with ECMAScript 5
* .
*/
"use strict";
let a = 1; // Correct
b = 1; // ReferenceError: b is not defined
Classes
Modern JavaScript supports classes and modules (use strict enabled by default).
/**
* In classes and modules, strict is enabled by default
*/
try {
class MyClass {
constructor() {
a = 1; // Look Here
}
}
new MyClass();
} catch (err) {
console.log(err.message); // a is not defined
}
➥ Questions