JS Flashcards
Escaping characters
Code Output \' single quote \" double quote \\ backslash \n newline \r carriage return \t tab \b word boundary \f form feed
Length of a string
“some text”.length
String values are…
Immutable. Which means that they cannot be altered once created. (this does not mean that myStr cannot be changed, just that the individual characters of a string literal cannot be changed)
multi-dimensional array
[[some content],[other content]]
Array values are…
Mutable. myArray[0] = 45;
.push() does…
appends data to an array
.pop() does…
pops and assigns the last element from an array to anything
.shift() does…
removes the first element of an array and returns it
.unshift() is…
like push but to the beginning of an array
structure of the function
function functionName() { console.log(something); }
Variables which are used without the var keyword…
…are automatically created in the global scope.
Variables which are declared within a function, as well as the function parameters…
… have local scope
It is ___ to have both local and global variables with the same name.
possible!
When you have both local and global variables with the same name…
… the local variable takes precedence over the global variable.
what is hoisting and what gets hoisted
adding vars and functions to memory when executing. they get added to the top of the file, so your function can be at the bottom but you can call it at the top
vars get partially hoisted (only var but not its value)
functions get fully hoisted
Variables which are defined outside of a function block have
Global scope. This means, they can be seen everywhere in your JavaScript code.
In JavaScript, scope refers to…
the visibility of variables
Variables which are used without the var keyword are…
automatically created in the global scope. This can create unintended consequences elsewhere in your code or when running a function again. You should always declare your variables with var.
It is possible to have both local and global variables with the same name. When you do this,
the local variable takes precedence over the global variable.
You can use a _ statement to send a value back out of a function.
return
A function can include the return statement but it does not have to. In the case that the function doesn’t have a return statement, when you call it,
the function processes the inner code but the returned value is undefined.
=== vs ==
unlike the equality operator, which attempts to convert both values being compared to a common type, the strict equality operator does not perform a type conversion.
determine the type of a variable or a value
typeof 3 // number
typeof ‘3’ // string
using logical AND
&&
the same effect: nest if statements