JavaScript - Intro Flashcards

1
Q

Explain Java vs. JavaScript

A
  • Both use dot syntax to drill down into nested objects.
  • Syntax is very similar.
  • Java is an object oriented programming language developed by Sun Microsystems that is capable of running on multiple operating systems with the use of an interpreter.
  • JavaScript, on the other hand, was created by Netscape as a scripting language. It cannot create stand alone applications, but instead resides within the browser.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Even though JavaScript is described as an ______- oriented language, there are no _______. It supports object-oriented programming by using object ________. (While ES6 has a class keyword, it is syntactic sugar over a prototype based structure)

A

Even though JavaScript is described as an object-oriented language, there are no classes. It supports object-oriented programming by using object prototypes. (While ES6 has a class keyword, it is syntactic sugar over a prototype based structure)

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

Everything inside of JavaScript is an ______. There are no clear distinctions between _____ and _______.

A

Everything inside of JavaScript is an object. There are no clear distinctions between types and objects.

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

Java is _____-based. Objects are divided into _____ and _______ with all inheritance through the class hierarchy.

A

Java is class-based. Objects are divided into classes and instances with all inheritance through the class hierarchy.

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

In JavaScript, _____ and ________ can be added to any object dynamically.

A

In JavaScript, properties and methods can be added to any object dynamically.

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

n Java, ______ and ______ cannot have properties or methods added dynamically.

A

In Java, classes and instances cannot have properties or methods added dynamically.

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

JavaScript is ______ typed. I can assign a String to a variable that was previously a number.

A

JavaScript is loosely typed. I can assign a String to a variable that was previously a number.

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

JavaScript objects are _______ arrays. Properties can be accessed via:

A

JavaScript objects are associative arrays.

Properties can be accessed via: obj.prop or obj[‘prop’].

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

JavaScript functions are _____ class members. They can be treated like ______ (can be assigned to ______ and passed around like ________)

A

JavaScript functions are first class members. They can be treated like objects (can be assigned to variables and passed around like variables)

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

JavaScript does not have to be _______.

A

JavaScript does not have to be compiled.

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

JavaScript’s access (through the browser) to the _____ system, _______, ________ on the machine etc is limited.

A

JavaScript’s access (through the browser) to the file system, databases, hardware on the machine etc is limited.

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

To add Javascript to your page:

A

Use script tags in the or . e.g. alert(“Hello World!”);

Separate file.using script tags. e.g. The type attribute is not absolutely required on the html5 spec.

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

Many developers put their script files at the _____ of the page, just before the closing body tag.

A

Many developers put their script files at the bottom of the page, just before the closing body tag.

It may improve performance and allows your page to load before it tries to access elements of your page.

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

If you need your JavaScript to run before the page loads, put your script files at the ______. If you need it to run before (or after) loading an element in your page, put it where you need it.

A

However, if you need your JavaScript to run before the page loads, put it at the top. If you need it to run before (or after) loading an element in your page, put it where you need it.

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

Ways to debug in Javascript:

A
  • alert() is convenient but obtrusive
  • Use console.log(); and the console in Chrome developer tools
  • Chrome developer tools can be used to view and manipulate elements and css, execute code, debug code, view resources, network timeline, request/response details, performance and profiling.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Variables hold ____ or different _____. Here is an example of defining a variable using the var keyword:

A

Variables hold values or different types.

Example:
//An example of variable definition using var
var x = 7; //integer (number)
x = 3.14 //float (number)
x = "Hello!"; //String
x = false; //Boolean
x = ["I", "am", "an", "array"]; //array
x = {name:"IMM", courses:10, awesome:true} //object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

List of types of values:

A
Number
String
Boolean
Array
Object
Function
Date
RegExp (used for pattern matching)
null (intentional absence of a value)
undefined (absence of a value;)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

There are three keywords we need to be aware of: ____, _____ and ____.

A
var x = "IMM"; 
let x = "IMM"; 
const x= "IMM";
19
Q

let has ____-level scope.
Var has _____-level scope.
const has _____-level scope and cannot be re-assigned a different value.

A

let has block-level scope.
Var has function-level scope.
const has block-level scope and cannot be re-assigned a different value.

20
Q

Always use the ______ keyword to define variable. Omitting that keyword will make your variable ______ and that may have unintended consequences.

A

Always use the var keyword to define variable. Omitting that keyword will make your variable global and that may have unintended consequences.

21
Q

5+5 == ?
5+”5” == ?
5*“x” == ?

A

5+5 == 10
5+”5” == “55”
5*“x” == NaN (Not a Number)

22
Q

if statement (SYNTAX)

A

if(condition){

}else{

}

23
Q

Operators:

equal to 
less than or equal to 
more than or equal to 
less than 
more than 
identical to 
not identical to 
equal to 
not equal to
A
equal to ==
less than or equal to <=
more than or equal to >=
less than <
more than >
identical to ===
not identical to !==
equal to ==
not equal to !=
24
Q

The difference between _____ and ______ rests in automatic type conversion. e.g. true == 1 and “2” == 2 but they are not identical.

A

The difference between equality and identity rests in automatic type conversion. e.g. true == 1 and “2” == 2 but they are not identical.

25
Q

String literals may be _____ to value of their _____ object counterparts but they are not _______ since they are a different type.

A

String literals may be equal to value of their String object counterparts but they are not identical since they are a different type.

26
Q

Boolean values evaluate to ____ for the following values: false, 0, empty strings (“”), NaN, null, and undefined.

All other values evaluate to _____.

A

Boolean values evaluate to false for the following values: false, 0, empty strings (“”), NaN, null, and undefined.

All other values evaluate to true.

27
Q

and: ?
or: ?
() Parentheses are used to group _____ _______.

A

and &&
or ||
() Parentheses are used to group complex comparisons

28
Q

All loops need to have an _____ that must be initialized, an ______ and a _______.

A

All loops need to have an index that must be initialized, an increment and a condition.

29
Q

while loop:

A
while(condition){
	//do this
}
30
Q

do, while loop:

A
do{
	//do this       
} while(condition)

statements within this loop gets executed at least once

31
Q

for loop:

A
for(var i=0; i<10; i++){
	//do something      
}
32
Q

for… of loop:

A
for (const currentValue of a) {
  // Do something with currentValue
}
33
Q

The keyword “_____” jumps out fo the loop entirely. The keyword continue will skip the rest of the iteration for that iteration of the loop.

A

The keyword “break” jumps out fo the loop entirely. The keyword continue will skip the rest of the iteration for that iteration of the loop.

34
Q

Create an array:

A
var arr = new Array();
var arr = []; //preferred literal syntax
35
Q

You can initialize an array with an ______ length although that length can be changed anytime.

A

You can initialize an array with an initial length although that length can be changed anytime.

var arr = new Array(5);

You can assign values using literal syntax.

var students = [“wasim”, “joe”, “Sam”];

36
Q

Another way of writing an array:

A
var students = [];   
 students[0] = "wasim"; 
 students[1] = "joe";
 students[2] = "Sam";
37
Q

Arrays may contain different types.

A

var studentInfo = [“George”, 181, true];

38
Q

Add values to the end of an array:

A

Add values to the end of an array: arrayObject.push();

39
Q

Return and remove last value in an array:

A

Return and remove last value in an array: arrayObject.pop();

40
Q

Extract values from an array: __________; begins extraction at index and ends at index 3

A

Extract values from an array: arraObject.slice(1,3); begins extraction at index and ends at index 3

41
Q

Find values in an array: ___________

A

Find values in an array: arrayObject.indexOf(“searchItem”);

42
Q

Math Object:

A
var flooredNumber = Math.floor(number); //returns the integer value of the number
var randomNumber = Math.random(); //returns a random number between 0 and 1
43
Q

Date Object:

A
var today = new Date(); //returns new date object based on today's date 
var notToday = new Date(2012,11,09); retuens a new date based on 9th Nov 2012.
dateObject.getMonth(); //returns the month
dateObject.getDay(); //returns the day
dateObject.setFullYear(2020,10,3); //sets the year, month and day of the current date object.
dateObject.getTime(); //returns the time,in milliseconds since Jan 01, 1970
44
Q

Common escape sequences:

A

\n new line
\t tab
\ backslash