JavaScript Flashcards
(113 cards)
Name the primitive types of javascript
- number 2. string 3. boolean 4. null 5. undefined
Describe lexical scoping
Lexical scoping, aka static scoping, refers to the process of determining a variable’s SCOPE based on its position within the body of code. For example, variables declared outside of a function have global scope, whereas variables declared inside a function have local scope (visible to members of the function only)
What is a lambda language
In simple terms, a lambda language is one that allows functions to be passed to other functions, with the passed function being treated like any other variable
In JavaScript, 1 and 1.0 are the same value because _
1 and 1.0 are the same value because JavaScript has no separate integer type, it has a single number type
Describe NaN
NaN is a number value that is the result of an operation that cannot produce a normal result. e.g. multiplying a number with a string
How can detect NaN
You can detect NaN by using the isNaN function, e.g. isNan( number)
In JavaScript, all characters are _ bit wide
16
In JavaScript, all numbers are _ bit floating-point
64
Strings are immutable. Describe
A string cannot be changed once its made. It is, however, easy to create a new string by concatenating other strings together using the + operator
What is a statement
A statement is a sentence or command, which ends with a semicolon. Statements make something happen, e.g. var name; is a statement that declares a variable called name
True or false, blocks in JavaScript do not create a new scope
True, blocks in JavaScript do not create a new scope, so variables should be defined at the top of a function, not in blocks
What are the falsy values?
- false 2. null 3. undefined 4. empty string ‘’ 5. number 0 6. NaN
Explain the switch statement
The switch statement performs a multiway branch by comparing the expression against cases for equality switch (expression){ case expression1 : (case can contain one or more expressions) //code to be executed break; case expression2: //code to be executed break; default: //code to be executed }
What is an expression
An expression is a phrase that can be evaluated into a value by the JavaScript interpreter. For example var name = “Succeed”
What is the global object
Its a common namespace where all top-level variables for all compilation units are stored
What are the advantages of JavaScript having a single number type?
- Problems of overflow in short integers are avoided 2. A large class of numeric type errors is avoided
When is it appropriate to use a switch statement?
It is appropriate to use a switch statement when you are testing an expression is based on a single integer, string, etc…as opposed to if-then-else which can be used with an expression based on ranges of values or conditions
What does the throw statement do?
The throw statement raises an exception. If it is part of a try/catch block, execution is passed to the catch clause
Describe an expression statement
An expression statement can: 1. assign values to one or more variables or members 2. invoke a method 3. delete an object property
Define a JavaScript object
A JavaScript object is a mutable container of properties, where each property has a name and a value pair
Demonstrate an object literal
var person = {
name : 'John', age : 30
};
JavaScript includes a _ feature that allows an object to _ the properties of _
JavaScript includes a prototype linkage feature that allows an object to inherit the properties of another object
When is it appropriate to use quotes around the name of an object property
It is appropriate to use quotes around the name of an object property when the name has a space eg
var person = {
“first name” : ‘John’
}
var animal = {
type : ‘dog’,
age : 2
}
console.log(animal.breed.breedType)
What is the outcome?
TypeError because there is no defined breed.breedType