mode 3 JavaScript Flashcards

1
Q

What is JavaScript?

A

It is a scripting programming language originally designed to provide functionality to webpages; effectively making those webpages dynamic. It allows websites clients to run code from their machines instead of always returning to the server for a new view/html container new information/calculations.

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

What is a scripting language?

A

It’s a snipped of interpreted code that automates some functionality.

A script is NOT a complete application/program, it’s just a snippet of code. By “interpreted” that means it runs line by line

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

What are features of JS?

A

Features of JS:

  • loosely typed; meaning a variable can hold ANY datatype > var i = 0; i= “hello”; i= false;
  • it’s a dynamic language; meaning you can heavily modify the structures during runtime
  • it has a JIT compiler (Just In Time): it is not compiled, it is interpreted
  • originally built for DOM manipulation, but it has evolved
  • generally, interpreted by the browser or nodejs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is DOM?

A

DOM= Document Object Model

The DOM is a virtual representation of the HTML page

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

What are the ways to run our JS file?

A

I can run a JS file using:
>using an HTML page that has the JS file linked via the script tag
>using “node [filepath]” in the terminal

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

what is console log?

A
It's basically a system.out.println for JS. It'll print the text to the developer tools console in the browser
// console.log("hello world");
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the datatypes in JS

A

Primitives and Reference types

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

What are primitives in JS

A

-boolean -number -string -null -undefined (in the latest ECMAScript there are BigInt & Symbols etc)

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

What is ECMAScript?

A

ECMAScript is a standardization of functionalities that scripting languages should have.
Various versions of ECMAScript add different functionalities.
e.g. it can be denoted like “ES6” or “ES2015” or “ECMAScript2015”

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

How can we declare variables in JS?

A

we can use “var” in order to declare variables. but we dont need to..

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

What are the Reference types in JS

A

-Objects -Array -Functions

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

How do we create an object in JavaScript?

A

var exampleObject= { }; //this is an empty object, but still an object

//look at this…we can have an object literal in JavaScript, unlike Java
//this is NOT the defition of a class….we are literally creating the instance right here
var exampleObjectTwo = {
“myAttr1”: “myValue”,
‘myAttr2’: 5
};

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

How do we create a function in JS?

A

There are 3 ways;

1st Way:
function exampleFunction(myVar1, myVar2){
    console.log("in our first func");
}

// exampleFunction(5, false); //this is how we invoke our function

2nd WAY to create a function while putting it into a variable
var exampleFunctionTwo = function (myVar) {
    console.log("in our second func: "+myVar);
};
3rd WAY to create a function USING A NOTATION called "arrow notation"
var exampleFunctionThree = (myOtherVar) => {
    console.log("in our third func: "+ myOtherVar);
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the typeof operator?

A

typeof returns a string that describes the datatype of the argument it is given. note array is a typeof object, as well as object is a typeof object. Function is a type of function

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

CONVERTING DATATYPES

Can we convert one datatype to another?

A

The answer is yes

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

STRING TYPE COERCION

What is type coercion?

A
  • it is the automatic conversion of a datype to another datatype
    • it triggers in a variety of situation

(Remember the ASCII table and Precedence order table)

// console.log(5+10+”stuff”+9+10); prints 15stuff910

17
Q
NUMERIC PRECISION IN JAVASCRIPT
What would the following print?
// console.log(1.1+1); 
// console.log(1.1+1.3); 
var precision = 1.1 +1.3;
// console.log(precision);
// console.log(precision.toFixed(2));
A
// console.log(1.1+1); //prints "2.1"
// console.log(1.1+1.3); //prints "2.40000000000004" instead of 2.4
var precision = 1.1 +1.3;
// console.log(precision);
// console.log(precision.toFixed(2)); prints 2.4
18
Q

What are the COMPARISON operators in JS?

A

== a double equals, or comparison, checks if the two values are equal then produces a true or false value. It WILL allow JS to utilize type coercion during this process

=== a triple equals, or strict comparison, checks if the two values are equal then produces a true or false value. It will NOT allow JS to utilize type coercion during this process

// console.log(5==4); //false
// console.log(5=="5"); //true
// console.log(5==="5"); //false