CH. 7 Syntax: Overview, strict/sloppy, Advanced, Statement vs expression, Identifiers Flashcards
Comments
Basic Constructs - comments
1) // single-line comment
2) /*
Comment with
multiple lines
*/
Booleans:
Basic constructs - Primitive (atomic) values
true
false
Numbers:
Basic constructs - Primitive (atomic) values
1.141
-123
The basic number type is used for both floating point numbers (doubles) and integers
Bigints:
Basic constructs - Primitive (atomic) values
17n
-49n
The basic number type can only properly represent integers within a range of 53 bits plus sign. Bigints can grow arbitrarily large in size.
Strings:
with Interpolated values:
Basic constructs - Primitive (atomic) values
‘abc’
“abc”String with interpolated values: ${256} and ${true}
- JavaScript has no extra type for characters. It uses strings to represent them.
An assertion describes what?
Basic constructs - Assertions
The result of a computation is expected to look like and throws
an exception if those expectations aren’t correct.
ex. assert.equal(7 + 1, 8);
example assertion states result 7 + 1 must be 8
assert.equal()
Basic constructs - Assertions
Is a method call (the object is assert, the method is .equal()) with two
arguments: the actual result and the expected result. It is part of a Node.js assertion API that is explained later
There is also assert.deepEqual()
Basic constructs - Assertions
compares objects deeply
console.log(‘Hello!’);
Basic constructs - Logging to the console or node.js
Printing a value to standard out (another method call)
console.error(‘Something went wrong!’);
Basic constructs - Logging to the console or node.js
Printing error information to standard error
Operators for booleans
Basic constructs - Operators
assert.equal(true && false, false); // And
assert.equal(true || false, true); // Or
Operators for numbers
Basic constructs - Operators
assert.equal(3 + 4, 7);
assert.equal(5 - 1, 4);
assert.equal(3 * 4, 12);
assert.equal(10 / 4, 2.5);
Operators for bigints
Basic constructs - Operators
assert.equal(3n + 4n, 7n); // add
assert.equal(5n - 1n, 4n); // minus
assert.equal(3n * 4n, 12n); // multiply
assert.equal(10n / 4n, 2n); // divide
Operators for strings
Basic constructs - Operators
assert.equal(‘a’ + ‘b’, ‘ab’);
assert.equal(‘I see ‘ + 3 + ‘ monkeys’, ‘I see 3 monkeys’);
Comparison operators
Basic constructs - Operators
- assert.equal(3 < 4, true); // > or <
- assert.equal(3 <= 4, true); // > or < equal to
- assert.equal(‘abc’ === ‘abc’, true); // strict equal
- assert.equal(‘abc’ !== ‘def’, true); // strict not equal
JavaScript has a == comparison operator recommend not using why is later
Other type of operators will be examined later