mode 3 JavaScript Flashcards
What is JavaScript?
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.
What is a scripting language?
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
What are features of JS?
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
What is DOM?
DOM= Document Object Model
The DOM is a virtual representation of the HTML page
What are the ways to run our JS file?
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
what is console log?
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");
What are the datatypes in JS
Primitives and Reference types
What are primitives in JS
-boolean -number -string -null -undefined (in the latest ECMAScript there are BigInt & Symbols etc)
What is ECMAScript?
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 can we declare variables in JS?
we can use “var” in order to declare variables. but we dont need to..
What are the Reference types in JS
-Objects -Array -Functions
How do we create an object in JavaScript?
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 do we create a function in JS?
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); };
What is the typeof operator?
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
CONVERTING DATATYPES
Can we convert one datatype to another?
The answer is yes