JAVASCRIPT Flashcards
Who originally developed JS?
Branden Eich.
What was JS originally called?
LiveScript
When was JS named JS? Why then?
LiveScript was renamed JavaScript in 1995, as it became a joint venture of Netscape and Sun.
Who standardized JS as ECMA-262?
The European Computer Manufacturers Association.
Is JS statically or dynamically typed?
Dynamically.
JS is solely a client side language.
False - it may be used server side as well.
Is JS case sensitive?
Yes.
What’s a synonym for dynamic typing?
Loose typing.
What is the root object in JS?
Object
What type of inheritance does JS exhibit?
Prototypal inheritance.
Is there polymorphism in JS?
No.
A web server is needed for JS.
False.
Write the html to import an external script.js file.
How can JS code be embedded into html?
<script> ... </script>
What are the ways to write comments in JS?
// …
/* … */
What JS object provides functions such as floor, round, max, min, etc?
Math
What are the 5 JS primitive types?
Number, String, Boolean, Undefined and Null.
Do the null type and the undefined type have several possible values?
No.
What is returned by an arithmetic operation that creates overflow?
NaN
What does (NaN == NaN) return?
False.
How should you check for NaN values?
isNaN(x)
What are the 4 ways of declaring a JS variable?
using var, let, const, or using nothing.
What operator coerces strings into numbers, and numbers into strings depending on the context?
+
List 2 ways of explicitly converting a number into a string.
Using the String constructor, or using a number’s toString() method.
List 2 ways of explicitly converting a string to a number.
Using the Number constructor, or using parseInt() / parseFloat() functions.
What does the following print?
console.log(1 + 2 + “bird”);
3bird
When does the + operator execute numeric addition, rather than concatenation?
Only when both operands are numbers.
What is the result of ‘$’ + 3 + 4 ?
$34
(left to right execution)
When does < or > execute a number comparison?
When both operands are numbers, or if one is a number and the other can be converted to a number.
When is the result of a < or > comparison always false?
When one operand is a number, the other isn’t and can’t be converted to a number.
What is the result of “11” < “2”?
True, because a string comparison is performed if both operands are strings.
What is the result of the following?
11 < 2+ “birds”
False, since the RHS becomes “2birds” which can’t be converted to a number in JS.
What is the result of the following?
‘$’ + 3 < 4
False - can’t convert ‘$3’ to a number.
When is * a number multiply?
If both operands are numbers, or both can be converted to a
number.
What is the result of a multiplication (*) wherein one of the operands cannot be converted to a number?
NaN
What is the result of the following?
‘$’*3 < 4
False.
Is there a character type in JS?
No.
How many bits are each character in a JS string?
16
How can characters be represented in JS?
As strings with a length of 1.
Are strings immutable in JS?
Yes.
The == operator can be used to check for value equality between 2 strings in JS.
True.
Do string literals use single or double quotes in JS?
Either.
How can you obtain the length of a string object?
str.length
What is the difference between ‘String(val)’ and new ‘String(val)’ ?
String(val) returns a string,
new String(val) returns an object.
What does the following code print?
var a = “123”;
var b = “123”;
document.write(a==b);
true
What method can return the character at a specified index, x, of a string, str?
str.charAt(x)
What method (not operator) can join two strings, s1 & s2, into a single string?
s1.concat(s2)
What method returns the index position of some character/substring str2 within str1?
str1.indexOf(str2)
What method returns the index position of some character/substring str2 within str1, and searches right to left?
str1.lastIndexOf(str2)
What method compiles all instances of a string (or regex), x, found within a string str, into an array it then returns?
str.match(x)
What method can replace all instances of str2 with str3, within str1?
str1.replace(str2, str3)
Does .replace() change the original string?
No, it returns a new one with the changes made.
What does the str.search(x) method do?
It returns the index (position) of the first match of x within str.
What does .search() return if no matches are found?
.search() returns -1.
What JS method returns a substring of str, between indices i1 and up to (but not including) i2?
str.slice(i1, i2)
What does str.split(“,”) do?
It splits str at its commas and returns an array of the resulting substrings.
What method behaves almost exactly str.slice(i1, i2)?
.substring()
Do the JS methods str.toUpperCase() and str.toLowerCase() put all characters of str to upper/lower case, or only the first?
All.
In JS, what non-Boolean equate to Boolean false? (6)
0, -0, “”, NaN, undefined, null.
In JS, “0” equates to what Boolean value?
True.
How can you explicitly convert a non Boolean to a Boolean value?
Boolean(val)
What does the following return?
Boolean(“false”);
true
What does the JS Date object’s .getTime() method return?
The number of milliseconds since January 1, 1970.
What JS object represents the model for the browser’s display window?
The Window object.
What’s the difference between the JS alert(msg) and confirm(msg) functions?
The confirm popup has an additional “cancel” button.
What does the JS prompt() function do?
Creates a popup window capable of accepting input.
What is the purpose of the optional second parameter of the prompt() method?
The optional second parameter specifies the default text within the input section of the popup.
What’s the difference between == / != and === / !== ?
=== / !== don’t do type coercion.
what does “123” == “123” return?
true
What does (3 !== “3”) return?
true
What is the output of the following?
var a = new String(“123”);
var b = new String(“123”);
document.write(a==b);
false, due to the (double) use of the new operator.
What is the output of the following?
var a = String(“123”);
var b = new String(“123”);
document.write(a==b);
true
&& and || always return Boolean values.
False - && returns the second operand if the first is truthy (else it returns the first) and || returns the first operand if it is truthy (else it returns the second).
! always returns a Boolean value.
True.
Explicitly convert a value to true or false without using Boolean(val).
!!val
How many bitwise operators are there in JS? List them.
6 - &, |, ~, ^, «,»_space;
What does the & operator do?
& ANDs the binary representations of its operands.
What does the | operator do?
It ORs the binary representations of its operands.
ORs
What does the ~ operator do?
It negates (flips) the binary representation of its operand.
What does the ^ operator do?
It XORs the binary representations of its operands.
What does the «_space;operator do?
It bit-shifts the binary representation of its first operand by n bits to the left, where n is the second operand.
What does the»_space; operator do?
It bit-shifts the binary representation of its first operand by n bits to the right, where n is the second operand.