CH. 7 Syntax: Overview, strict/sloppy, Advanced, Statement vs expression, Identifiers Flashcards

1
Q

Comments

Basic Constructs - comments

A

1) // single-line comment
2) /*
Comment with
multiple lines
*/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Booleans:

Basic constructs - Primitive (atomic) values

A

true
false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Numbers:

Basic constructs - Primitive (atomic) values

A

1.141
-123
The basic number type is used for both floating point numbers (doubles) and integers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Bigints:

Basic constructs - Primitive (atomic) values

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Strings:
with Interpolated values:

Basic constructs - Primitive (atomic) values

A

‘abc’
“abc”
String with interpolated values: ${256} and ${true}
- JavaScript has no extra type for characters. It uses strings to represent them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

An assertion describes what?

Basic constructs - Assertions

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

assert.equal()

Basic constructs - Assertions

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

There is also assert.deepEqual()

Basic constructs - Assertions

A

compares objects deeply

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

console.log(‘Hello!’);

Basic constructs - Logging to the console or node.js

A

Printing a value to standard out (another method call)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

console.error(‘Something went wrong!’);

Basic constructs - Logging to the console or node.js

A

Printing error information to standard error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Operators for booleans

Basic constructs - Operators

A

assert.equal(true && false, false); // And
assert.equal(true || false, true); // Or

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Operators for numbers

Basic constructs - Operators

A

assert.equal(3 + 4, 7);
assert.equal(5 - 1, 4);
assert.equal(3 * 4, 12);
assert.equal(10 / 4, 2.5);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Operators for bigints

Basic constructs - Operators

A

assert.equal(3n + 4n, 7n); // add
assert.equal(5n - 1n, 4n); // minus
assert.equal(3n * 4n, 12n); // multiply
assert.equal(10n / 4n, 2n); // divide

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Operators for strings

Basic constructs - Operators

A

assert.equal(‘a’ + ‘b’, ‘ab’);
assert.equal(‘I see ‘ + 3 + ‘ monkeys’, ‘I see 3 monkeys’);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Comparison operators

Basic constructs - Operators

A
  • 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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does const create?

Basic constructs - Declaring variables

A

const creates immutable variable bindings: Each variable must be initialized immediately and we can’t assign a different value later. However, the value itself may be mutable and we may be able to change its contents.

In other words: const does not make values immutable.

17
Q

Declaring and initializing x (immutable binding):

Basic constructs - Declaring variables

A

const x = 8;
// Would cause a TypeError: x = 9;

const x = immutable x

18
Q

let creates mutable variable bindings:

Basic constructs - Declaring variables

A

// Declaring y (mutable binding):
let y;
// We can assign a different value to y:
y = 3 * 5;
// Declaring and initializing z:
let z = 3 * 5;

19
Q

Create add1() the parameters are a and b:

Basic constructs - Ordinary function declarations

A

Function add1(a, b) {
return a + b;
}

20
Q

Calling function add1()

Basic constructs - Ordinary function declarations

A

ex. assert.equal(add1(5, 2), 7);

21
Q

What are Arrow function expressions

Basic contructs - arrow function expressions

A

Arrow function expressions are used especially as arguments of function calls and method calls

const add2 = (a, b) => { return a + b };

22
Q

How do you call a Arrow function expression?

Basic contructs - arrow function expressions

A

** Calling functionadd2():**
assert.equal(add2(5, 2), 7);

mind: const add2 = (a, b) => { return a + b };

23
Q

Equivalent to add2 arrow function call:

Basic contructs - arrow function expressions

A

const add3 = (a, b) => a + b;

mind: const add2 = (a, b) => { return a + b };

24
Q

An arrow function whose body is a code block call:

Basic contructs - arrow function expressions

A

(a, b) => { return a + b }

25
Q

An arrow function whose body is an expression call:

Basic contructs - arrow function expressions

A

(a, b) => a + b

26
Q

Creating a plain object via an object literals

Basic contructs - Plain objects

A

const obj = {
first: ‘Jane’, // property
last: ‘Doe’, // property
getFullName() { // property (method)
return this.first + ‘ ‘ + this.last;
},
};