Chapter 3: Variables Flashcards

(47 cards)

1
Q

JavaScript types can be divided into two categories: ______ types and ______ types

A

primitive, object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

The special JavaScript values null and undefined are _______ values, but they are not
numbers, strings, or booleans

A

primitive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Any JavaScript value that is not a number, a string, a boolean, or null or undefined is
an _____

A

object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

JavaScript defines another special kind of object, known as a ______

A

function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The most important thing about functions in JavaScript is that
they are true values and that JavaScript programs can treat them like _____

A

objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Functions that are written to be used (with the new operator) to initialize a newly created
object are known as ______

A

constructors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Javascript types can be categorized as _____ and _____ types

A

mutable, immutable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

In javascript, strings are immutable

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

JavaScript converts values liberally from one type to another. If a program expects a
string, for example, and you give it a number, it will automatically convert the number
to a string for you

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When a number appears directly in a JavaScript program, it’s called a _____ _______

A

numeric literal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Javascript recognizes hexadecimal

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

All numbers in JavaScript are represented as floating-point
values.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

JavaScript supports more complex
mathematical operations through a set of functions and constants defined as properties
of the ______ object:

A

Math

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

There are infinitely many real numbers, but only a finite number of them
(18437736874454810627, to be exact) can be represented exactly by the JavaScript
floating-point format. This means that when you’re working with real numbers in
JavaScript, the representation of the number will often be an ______ of the
actual number.

A

approximation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Core JavaScript includes a _____ constructor for creating objects that represent dates
and times.

A

Date()
var then = new Date(2010, 0, 1); // The 1st day of the 1st month of 2010
var later = new Date(2010, 0, 1, // Same day, at 5:10:30pm, local time
17, 10, 30);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

In javascript a string is _____

A

immutable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

To include a string literally in a JavaScript program, simply enclose the characters of
the string within a matched pair of ____ or _____

A

single, double quotes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

____ is an escape sequence that represents a newline character

A

\n

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

One of the built-in features of JavaScript is the ability to _________ strings. If you use
the ____ operator with numbers, it adds them

A

concatenate, +

20
Q

In addition to this
______ property, there are a number of methods you can invoke on
strings

A

length
s.length

21
Q

Remember that strings are immutable in JavaScript. Methods like replace() and
toUpperCase() return new strings: they do not modify the string on which they are
invoked

22
Q

____ and _____ for boolean values

23
Q

Boolean values have a _______ method that you can use to convert them to the strings
“true” or “false”

24
Q

______ is a language keyword that evaluates to a special value that is usually used to
indicate the absence of a value.

25
The ______ object is a regular JavaScript object that serves a very important purpose: the properties of this object are the globally defined symbols that are available to a JavaScript program
global
26
In top-level code—JavaScript code that is not part of a function—you can use the JavaScript keyword _____ to refer to the global object:
this
27
When the value of a property is a function, we call it a _______. To invoke the method m of an object o, we write ____
method, o.m()
28
Strings are not objects, though, so why do they have properties? Whenever you try to refer to a property of a string s, JavaScript converts the string value to an object as if by calling ____ ______. This object inherits (see §6.2.2) string methods and is used to resolve the property reference
new String(s)
29
Numbers and booleans have methods for the same reason that strings do: a temporary object is created using the _____ or _______ constructor
Number), Boolean()
30
The temporary objects created when you access a property of a string, number, or boolean are known as ______ ______
wrapper objects
31
The _____ operator will also show you the difference between a primitive value and its wrapper object.
typeof
32
Objects are not compared by value: two objects are not equal even if they have the same properties and values. And two arrays are not equal even if they have the same elements in the same order:
TRUEEEEE
33
JavaScript is very flexible about the types of values it requires. We’ve seen this for booleans: when JavaScript expects a boolean value, you may supply a value of any type, and JavaScript will convert it as needed.
True
34
Because JavaScript can convert values flexibly, its == _______ ______ is also flexible with its notion of equality
equality operators null == undefined // These two values are treated as equal. "0" == 0 // String converts to a number before comparing. 0 == false // Boolean converts to number before comparing. "0" == false // Both operands convert to numbers before comparing.
35
The simplest way to perform an explicit type conversion is to use the ______, ______, ______, or ______ functions
Boolean(), Number(), String(), Object()
36
______ parses only integers, while _______ parses both integers and floating-point numbers.
parseInt(), parseFloat()
37
Both parseInt() and parseFloat() skip leading _______, parse as many numeric characters as they can, and ignore anything that follows. If the first nonspace character is not part of a valid numeric literal, they return _____:
NaN
38
all objects (including arrays and functions) convert to ____. This is so even for wrapper objects: new Boolean(false) is an object rather than a primitive value, and so it converts to true.
true
39
All objects inherit two conversion methods. The first is called ______, and its job is to return a string representation of the object.
toString()
40
The other object conversion function is called ________
valueOf()
41
Variables are declared with the ____ keyword
var var i; var sum;
42
If you don’t specify an initial value for a variable with the var statement, the variable is declared, but its value is ________ until your code stores a value into it
undefined
43
The ____ of a variable is the region of your program source code in which it is defined.
scope
44
Function definitions can be nested
True
45
This is called block scope, and JavaScript does not have it
True
46
java script has ______ ______: variables are visible within the function in which they are defined and within any functions that are nested within that function. This means that even if a variabel is declared below but is used futrther up, if it is defined it is still valid because of _____ ____
function scope
47
Since JavaScript does not have block scope, some programmers make a point of declaring all their variables at the ____ of the function
top