Variables, Declarations and Assignment Flashcards

1
Q

What is the **<script>** tag, what are its two key attributes, and how does webpack use it?

A

The <script> tag allows us to inject JavaScript code into the browser either directly in the tag or by defining a src="example/file-location.js".

Traditionally a type="text/javascript" attribute was needed to tell the browser what type of code to expect, but this is now inferred thanks to HTML5 and is unecessary.

Because JavaScript is run top-to-bottom it is important to place the <script> tag just before the closing </body> tag to ensure the document has been fully loaded by the browser before running any code.

If using Webpack, webpack will automatically generate a bundle of all the project JS code called main.bundle.js, and add a <script> tag to your HTML with src="main.bundle.js".

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

What is the reserved keyword var used for?

A
var
is a JavaScript keyword for creating unique identifiers which store mutable values.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why is JavaScript considered a dynamically typed language?

A

JavaScript is considered a dynamically typed language because variable types are mutable, or dynamic.

Ex: A variable that was initialized as a number can become a string.

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

What is varibale decleration?

A

Variable decleration is when a unique identifier is declared using either var, let, or const.

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

What are the three JavaScript keywords for declaring variables?

A

The three JavaScript keywords for declaring variables are var, let, and const.

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

What is variable initialization?

A

Variable initialization is when a variable is given a value with the = operator.

Ex: const a = 10; - variable a is declared & initialized to number 10.

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

What is variable hoisting?

A

Hoisting refers to the process that the JavaScript engine uses to bring declared variable names to the top of the script automatically.

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

What is the let statement in JavaScript?

A

let is a keyword in JavaScript used for declaring variables. The main difference between let and var is in regard to scoping of the variables.

Whereas var is function scoped, let is block scoped. This means that variables declared with var are accesible in the global scope, whereas variables declared with let are only available inside the block they are declared in. let is also not accesinle before initialzation, wherease var is.

Use let if you will need to rebind a variable.

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

What is the const statement in JavaScript?

A

const is a JavaScript keyword used for declaring variables which cannot be re-bound, i.e. they cannot change value once initialized.

Best practice is to use const by default.

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