JavaScript Flashcards

1
Q

What is JavaScript

A

Javascript is used by programmers across the world to create dynamic and interactive web content like applications and browsers.

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

Semicolons ;

A

Semicolons separate JavaScript statements.
let a, b, c; // Declare 3 variables
a = 5; // Assign the value 5 to a
b = 6; // Assign the value 6 to b
c = a + b; // Assign the sum of a and b to c

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

JavaScript Values

A

The JavaScript syntax defines two types of values:

Fixed values

Variable values

In a programming language, variables are used to store data values.

JavaScript uses the keywords var, let and const to declare variables.

An equal sign is used to assign values to variables.

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

JavaScript and Camel Case

A

Hyphens are not allowed in JavaScript. They are reserved for subtractions. firstName, lastName, masterCard, interCity.

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

JavaScript Comments

A

//

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

4 Ways to Declare a JavaScript Variable

A
4 Ways to Declare a JavaScript Variable:
Using var
Using let
Using const
Using nothing
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When to Use JavaScript const?

A

If you want a general rule: always declare variables with const.

If you think the value of the variable can change, use let.

The two variables price1 and price2 are declared with the const keyword.

These are constant values and cannot be changed.

The variable total is declared with the let keyword.

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

JavaScript Let

A
Variables defined with let cannot be Redeclared.
let x = "John Doe";

let x = 0;

// SyntaxError: ‘x’ has already been declared

Variables defined with let must be Declared before use.

Variables defined with let have Block Scope.

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

Block Scope

A

Block Scope in JavaScript.

Variables declared inside a { } block cannot be accessed from outside the block:

{
  let x = 2;
}
// x can NOT be used here

Variables declared with the var keyword can NOT have block scope.

Variables declared inside a { } block can be accessed from outside the block.

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

Block Scope and LET

A

Redeclaring a variable inside a block will not redeclare the variable outside the block:

let x = 10;
// Here x is 10
{
let x = 2;
// Here x is 2
}

// Here x is 10

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

JavaScript Const

A

Variables defined with const cannot be Redeclared.

Variables defined with const cannot be Reassigned.

Variables defined with const have Block Scope.

JavaScript const variables must be assigned a value when they are declared:

Use const when you declare:

A new Array
A new Object
A new Function
A new RegExp

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

Arrays with CONST

A
// You can create a constant array:
const cars = ["Saab", "Volvo", "BMW"];
// You can change an element:
cars[0] = "Toyota";
// You can add an element:
cars.push("Audi");
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Constant Objects

A
// You can create a const object:
const car = {type:"Fiat", model:"500", color:"white"};
// You can change a property:
car.color = "red";
// You can add a property:
car.owner = "Johnson";
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

3 data types

A
let length = 16;                               // Number
let lastName = "Johnson";                      // String
let x = {firstName:"John", lastName:"Doe"};    // Object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

JavaScript Functions

A

A JavaScript function is a block of code designed to perform a particular task.

A JavaScript function is executed when “something” invokes it (calls it).

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

Functions example

A
function myFunction(p1, p2) {
  return p1 * p2;   // The function returns the product of p1 and p2
}
function name(parameter1, parameter2, parameter3) {
  // code to be executed
}
17
Q

Function parameters, arguments

A

Function parameters are listed inside the parentheses () in the function definition.

Function arguments are the values received by the function when it is invoked.

Inside the function, the arguments (the parameters) behave as local variables.

18
Q

Function Invocation

A

When an event occurs (when a user clicks a button)
When it is invoked (called) from JavaScript code
Automatically (self invoked)