JS Fundamentals - Variables Flashcards

1
Q

to declare variable

A

use let

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

multi line variabes

A
let user = 'John',
  age = 25,
  message = 'Hello';

Or even in the “comma-first” style:

let user = 'John'
  , age = 25
  , message = 'Hello';
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

variable namings

A

The name must contain only letters, digits, or the symbols $ and _.
The first character must not be a digit.

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

case matters

A

Variables named apple and AppLE are two different variables.

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

Non-Latin letters are allowed, but not recommended

A

let имя = ‘…’;

let 我 = ‘…’;

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

Reserved names

A

There is a list of reserved words, which cannot be used as variable names because they are used by the language itself.

For example: let, class, return, and function are reserved.

The code below gives a syntax error:

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

constants

A

const myBirthday = ‘18.04.1982’;

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

uppercase constants

A

Uppercase constants

Being a “constant” just means that a variable’s value never changes. But there are constants that are known prior to execution (like a hexadecimal value for red) and there are constants that are calculated in run-time, during the execution, but do not change after their initial assignment.

For instance:

const pageLoadTime = /* time taken by a webpage to load */;
The value of pageLoadTime is not known prior to the page load, so it’s named normally. But it’s still a constant because it doesn’t change after assignment.

In other words, capital-named constants are only used as aliases for “hard-coded” values.

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

Summary

A

let – is a modern variable declaration.
var – is an old-school variable declaration. Normally we don’t use it at all, but we’ll cover subtle differences from let in the chapter The old “var”, just in case you need them.
const – is like let, but the value of the variable can’t be changed.
Variables should be named in a way that allows us to easily understand what’s inside them.

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