Variables Flashcards

1
Q

What is a variable?

A

A variable is a “named storage” for data.

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

How do you create a Variable?

A

To create a variable, use the let keyword.

let message;

message = ‘Hello’;

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

how do you create an unchanging Variable?

A

To declare a constant (unchanging) variable, use const instead of let:

const myBirthday = ‘18.04.1982’;

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

There are two limitations on variable names in JavaScript:

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

Case matters

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

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
6
Q

What is Variable Scope?

A

The scope of a variable is the part of the program where the variable is visible. Variables declared with let or const are block-scoped. A code block is a portion of a program delimited by a pair of opening and closing curly braces { … }.

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

What are the main properties of a Variable?

A

A variable has three main properties:

1.) Its name, which identifies it. A variable name may contain upper and lower case letters, numbers (not in the first position) and characters like the dollar sign ($) or underscore (_).
2.) Its value, which is the data stored in the variable.
3.) Its type, which determines the role and actions available to the variable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are Type Conversions?

A

1.) An expression’s evaluation can result in type conversions. These are called implicit conversions, as they happen automatically without the programmer’s intervention.
(e.g)
const f = 100;
// Show “Variable f contains the value 100”
console.log(“Variable f contains the value “ + f);

2.) Sometimes you’ll wish to convert the value of another type. This is called explicit conversion. JavaScript has the Number() and String() commands that convert the value between the parenthesis to a number or a string.
(e.g)
const h = “5”;
console.log(h + 1); // Concatenation: show the string “51”
const i = Number(“5”);
console.log(i + 1); // Numerical addition: show the number 6

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