Javascript Flashcards

1
Q

What keyword should you not forget when assigning a variable’s value for the first time?

A

var

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

Which logical operator should I use when comparing values and why or why not?

A

the === or !== is best because it compares the value and the type where as the == or != compares and performs a type conversion

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

What are considered false values

A

undefined, null, 0, false, NaN, ‘ ‘ (empty string)

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

What should you always use to terminate your line?

A

semi-colon ;

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

What is an object constructor function?

What does the ‘this’ keyword do?

A
Javascripts way to create an "object type" or blueprints/classes.  An example would be:
function Person(first, last, age, eye) {
this.firstname = first;
this.lastname = last;
this.age = age;
this.eyeColor = eye;
}
The this is the object itself and it 'owns' the code.  In other words when a new Person is instantiated, the this will become the new objects.
var myFather =  new Person('John', 'Smith', '35', 'blue');
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what does typeof return?

A

It returns the datatype

console. log(typeof 42);
output: number
console. log(typeof arr);
output: object

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

How do you add a new property to an existing object?

A

myFather.nationality = “Irish”;

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

How do you add a method to an object?

A

myFather.name = function () {
return this.firstname + “ “ + this.lastName;
};
this method will be added to myFather only

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

How do you add a method to a Constructor?

A
function Person(first, last, age, eye) {
this.firstname = first;
this.lastname = last;
this.age = age;
this.eyeColor = eye;
this.name = function () {
        return this.firstname + " " + this.lastName;};
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are Javascript’s built-in constructors?

A
var x1 = new Object();    // A new Object object
var x2 = new String();    // A new String object
var x3 = new Number();    // A new Number object
var x4 = new Boolean();   // A new Boolean object
var x5 = new Array();     // A new Array object
var x6 = new RegExp();    // A new RegExp object
var x7 = new Function();  // A new Function object
var x8 = new Date();      // A new Date object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are Javascript literals?

A

JS primitive values that make writing code faster.

Use object literals {} instead of new Object().
Use string literals "" instead of new String().
Use number literals 12345 instead of new Number().
Use boolean literals true / false instead of new Boolean().
Use array literals [] instead of new Array().
Use pattern literals /()/ instead of new RegExp().
Use function expressions () {} instead of new Function().
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an anonymous function?

A
A function that executes automatically when you create it.  aka Self-Invoking function. Example:
(function () {
var x = "Hello";  //It will invoke itself without being called
})();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you get a random item from an array?

A
var items = [1,2,3,4,5]
var randomItem = items[Math.floor(Math.random() * items.length)]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does the function math.floor() work?

A

it returns the largest integer less than or equal to a given number

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

How does the function math.random() work?

A

it returns a floating-point number in the range of 0-1 (not including 1)

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

What is return?

A

when evoked it is a value that is returned to the caller when the function finishes executing

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

What is a caller?

A

a caller inserts values (whether it is from the function’s argument or return) between the { } when it executes the function. Once executed, the value is copied in and are available like any other variable.

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

What is a parameter?

A
a value that is passed through a function so that the function can behave differently depending on the value that is passed.  e.g.:
function greetSomeone(person) {
}  person is the paramenter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is an argument?

A

argument is the value that is passed through the function to invoke it. e.g.:
greetSomeone(‘Maika’) Maika is the argument

20
Q

What is a string?

A

a sequence of characters

21
Q

What is a boolean?

A

a true/false value

22
Q

What is the logical operator for and, or and not?

A

&&, ||, !

23
Q

What are array methods for javascript?

A

arr. push (adds a value to the end of the array)
arr. pop (removes and returns the value in an array)
arr. length (gives you the length of the array)

24
Q

How do you change the value or call the value of an array?

A

arr[1] = 3

arr[1]

25
Q

How do you iterate through an array with a for loop?

A
var arr = [1,2,3,5,8,8]
for (var i=0; i
26
Q

What is the sigma() function and how do you use it?

A

given a number, it returns the sum of all positive integers up to and including the number. eg.
sigma(3)
output: 6 // means 1 + 2 + 3

27
Q

What is factorial and how do you use it?

A

given a number, it returns the product of all positive integers up to and including the number. eg.
factorial(3)
output: 6 // means 1 * 2 * 3

28
Q

What is the modulo operator?

A

given 2 numbers, it divides the second number into the first number an integer number of times and returns the remainder. eg.
34 % 6
output: 4 //means 34/6 = 5 remainder 4

29
Q

How do you declare a string and what are its methods?

A
var myString = "Hello, World!!"
var myArray = ['I am a sentence, split me']

myString.length (returns the length of the string)

myArray.split(“ “) (returns array with split on every space)
output: [‘I’, ‘am’, ‘a’, ‘sentence,’, ‘split’, ‘me’]

myArray.join( ) (returns array with join on , by default
output: [‘I,am,a,sentence,,split,me’]

myArray.join(“-“) (returns array with join -
output:[‘I-am-a-sentence,-split-me’]

myArray.join(“”) (returns array without a delimiter)
output:[‘Iamasentence,splitme’]

30
Q

How does a switch statement work?

A

similar to if statements, and is based on a single value. Execution jumps forward to the case that matches or default if none is found. eg:

const month = new Date().getMonth();

switch (month) {
    // January, February, March
    case 0:
    case 1:
    case 2:
        console.log("Winter");
        break;
    // April, May, June
    case 3:
    case 4:
    case 5:
        console.log("Spring");
        break;
    // July, August, September
    case 6:
    case 7:
    case 8:
        console.log("Summer");
        break;
    // October, November, December
    case 9:
    case 10:
    case 11:
        console.log("Autumn");
        break;
    default:
        console.log("Something went wrong.");
}
31
Q

What is the const declaration?

A
it creates a read-only reference to a value in the global memory.  It does not mean the value it holds is immutable, it just means it cannot be reassigned.  eg:
const myfavnum = 3
myfavnum = 20 will throw an error
you can create a function that changes it when its invoked, that's the extent of it.
However,
objects are not necessarily protected:
const myObject = {'Animal': 'cat'}
myObject.key = 'dog'
key is immutable, but value is not
32
Q

What is a pattern?

A

A pattern is a reusable solution that can be applied to commonly occurring problems in software design - in our case - in writing JavaScript web applications. Another way of looking at patterns are as templates for how we solve problems - ones which can be used in quite a few different situations.

33
Q

Define code.

A

is a set of special instructions to tell the computer what tasks to perform. Usually code is saved in a text file, although with JavaScript you can also type code directly into a developer console in a browser.

34
Q

Define syntax.

A

In computer language it is the rules for valid format and combinations of instructions.

35
Q

Define statement.

A

a group of words, numbers, and operators
that performs a specific task. e.g.
a = b * 2;

36
Q

Define variable.

A

symbolic placeholders that hold values.

37
Q

Define operators.

A

perform actions with the values and variables such as assignment and mathematics.

38
Q

Define expressions.

A

any reference to a variable or value, or a set of variable(s) and
value(s) combined with operators.
For example:
a = b * 2;
This statement has four expressions in it:
• 2 is a literal value expression.
• b is a variable expression, which means to retrieve its current
value.
• b * 2 is an arithmetic expression, which means to do the multiplication.
• a = b * 2 is an assignment expression, which means to assign
the result of the b * 2 expression to the variable a (more on
assignments later).

39
Q

Define call expression statement.

A

A more common expression statement where the entire statement is the function call expression itself:
alert( a );

40
Q

What does it mean to execute a program?

A

running the program

41
Q

What is a high level definition of an interpreter or compiler?

A

A special utility on the computer that is used to translate the code you write into commands
a computer can understand.

42
Q

What does it mean to interpret the code?

A

A translation of commands that is typically done from top to bottom, line by line, every time the program
is run.

43
Q

What does it mean to compile the code?

A

A translation of commands that is typically done ahead of time, so when the program runs later, what’s running
is actually the already compiled computer instructions ready to go.

44
Q

What type of language is Javascript?

A

An interpreted language, because your Java‐
Script source code is processed each time it’s run. But that’s not entirely accurate. The JavaScript engine actually compiles the program
on the fly and then immediately runs the compiled code.

45
Q

What is the console.log() function?

A

The command is used to print/output text to the user in the developer console. The log part is referred to as a function call. It takes some value and prints it to the console. The console part is an object reference where the log() function is located.

46
Q

How does the alert() function work?

A

similar to the log function but instead it creates an output you can see as a pop-up.