Javascript Flashcards
(59 cards)
What is Javascript
Js is a programming language that is
- lightweight
- cross platform
- object oriented
- one of three core technologies
- commonly used in webpages
Can you use js in the server end?
Yes with node.js
How do you add js to a webpage?
you either add the code in a script tag in the html file
or you create a new js file and add a script source in the html
ex
what is a variable?
A variable is a container in which we can store values
how do you declare variables in js?
var name = ‘Name’;
What are datatypes?
there are different types of values
What kind of datatypes are there in js?
- numbers( always have floats)
- strings
- booleans
- Undefined(datatype that does not have a value yet)
- Null (non existent)
What is dynamic typing?
Dynamic typing means that js understands what kind of datatype you are working with.
How do you comment out code in javascript?
- single line comment //
- multiline comment /* stuff */
What is type coercion?
Type conversion means that javascript will transform the datatype to another by itself
Can we declare a variable without declaring a value to that?
Yes that is possible in javascript, the output will be shown as “undefined”.
What is a variable mutation?
Variable mutation is when we assign variables new values.
What is the difference between arguments and parameters?
Argument is what the user passes in when the function is called.
A parameter is the placeholders for arguments in the function.
How do you call a function in Javascript?
var someThing = function(argument);
How do you write function statements?
function someFun(parameter { //code }
How do you write a function statement?
var someFun = function(parameter) { // code }
What is the difference between a function expression and a function statement?
A function statement performs an action
A function expression produces a value
How do you create an array in js?
var name = ['john', 'jane', 'mark'] or var years = new Array(1990, 1999, 1948)
How do you get an object from an array?
names[0];
index in js are zero based (the start from zero)
What are some array functions?
.push(‘something’); adds an element in the end
.unshift(‘something’); adds an object in the beginning
.pop( ); deletes the last element
.shift( ); deletes the first element
.indexOf(‘something’); shows the index of that element in an array
What are objects in js?
objects are key value pairs
What is a for loop?
the for loop loops through a block of code a number of times.
the for loop is the most used loop in javascript
for (var i = 0; 1 < 20; i++) {
console.log(i);
}
what is the .length method?
the lenght method tells us how many elements there are in an array.
What is a while loop?
The while loop runs a block of code while the condition is true. var i = 0; while( i < names.lenght) { console.log(names[i]); }