TYPES, VALUES, and VARIABLES Flashcards
(92 cards)
1) What type of programming language is javaScript?:-
javascript is a high-level, dynamic, interpreted programming language that is well-suited for object-oriented and functional programming styles.
-> javascript variables are untyped.
2) How do you run a js file with node?:-
$ node filename.js (in terminal)
3) What is a programming language’s(e.g javaScript) lexical structure?:-
it is the set of elemenary rules that specify how you write programs in that language. (aka) the lowest-level of synax of a language.
4) What are the types of comments in js:-
single-line(//) multi-line(/**/) (Comments may not be nested)
5) There are three exceptions to the general rule that javaScript interprets line breaks as semicolons when it cannot parse the second line as a continuation of the statement in the first line?:-
-> The first exception invloves the return, throw, yeild, break and continue statement.(These statements often stand alone, but sometime are followed by an identifier or expression.)
-> The second exception involves the ++ and −− operators.
-> The third excep‐ tion involves functions defined using concise “arrow” syntax: the => arrow itself must appear on the same line as the parameter list.
6) JavaScript type are divided into two categories: namely?:-
primitive types and objects types.
* Primitives are immutable: there is no way to change (or “mutate”) a primitive value.
* Primitives are also compared by value: two values are the same only if they have the same value.
7) JavaScript primitive types include (name 3)?:-
numbers, strings(Strings of text) and boolean truth values
* Primitives are immutable: there is no way to change (or “mutate”) a primitive value.
* Primitives are also compared by value: two values are the same only if they have the same value.
8) JavaScript has two additional primitive types that are not numbers, strings or booleans. Name them?:-
the special values null and undefined. (each value is considered to be the sole member of its own special type)
* Primitives are immutable: there is no way to change (or “mutate”) a primitive value.
* Primitives are also compared by value: two values are the same only if they have the same value.
9) In ES6 Symbol was added as a?:-
new special-purpose type, that enables the definition of language extensions
without harming backword compatibility.
* Symbols were introduce to serve as no-string property names.
* To understand Symbols, you need to know that JavaScript’s fundamental Object type is an unodered collection of
properties, where each property has a name and a value. Property names are typically
(and until ES6, were exclusively) strings. But in ES6 and later, Symbols can also serve this purpose:
let strname = “string name”; // A string to use as a property name
let symname = Symbol(“propname”); // A Symbol to use as a property name
typeof strname // => “string”: strname is a string
typeof symname // => “symbol”: symname is a symbol
let o = {}; // Create a new object
o[strname] = 1; // Define a property with a string name
o[symname] = 2; // Define a property with a Symbol name
o[strname] // => 1: access the string-named property
o[symname] // => 2: access the symbol-named property
- The Symbol type does not have a literal syntax. To obtain a Symbol value, you call the Symbol() function.
- This function never returns the same value twice, even when called with the same argument.
This means that if you call Symbol() to obtain a Symbol value, you can safely use that value as a property
name to add a new property to an object and do not need to worry that you might be overwriting an
existing prop‐erty with the same name. Similarly, if you use symbolic property names and
do not share those symbols, you can be confident that other modules of code in your program will
not accidentally overwrite your properties. - The Symbol() function takes an optional string argument and returns a unique Sym‐ bol value.
If you supply a string argument, that string will be included in the output of the Symbol’s toString() method.
Note, however, that calling Symbol() twice with the same string produces two completely different Symbol values.
let s = Symbol(“sym_x”);
s.toString() // => “Symbol(sym_x)”
10) What is an object?:-
any javaScript value that is not a number, string, boolean, null, undefined
or Symbol (that is a member of the type object).
11) What is an ordinary javaScript objetc?:-
is an unordered collection of named values.
12) JavaScript defines a special kind of object called?:-
an array (an ordered collection of numbered values)
13) In addition to basic/ordinary objects and arrays javaScript defines other useful types of object. Name
those 5 objects?:-
-> A Set object respesents a set of values.
-> A Map object represents a mapping from values to keys.
-> Various “typed array” types facilitate operations on arrays of bytes and other binary data.
-> The RegExp type represents textual patterns and enables sophisticated matching, searching, and replacing
operations on strings.
-> The Date type represents dates and times and supports rudimentary date arthimetics.
-> Error and its subtypes represents errors that can arise will running javaScript code.
14) In javaScript which two values can method not be invoked on?:-
null and undefined.
15) JavaScript objects are mutable and its primitive types are immutable. what does that mean?:-
-> Mutable types can change.
-> Immutable types cannot change. (Strings can be thought of as arrays of characters but they are immuntable)
16) JavaScript constants and variables are untyped. What does that mean?:-
declaractions do not specify what kind of values will be assigned.
17) The javaScript number format allows you to exactly represent all integers btw?:-
−9,007,199,254,740,992 (−25^3) and 9,007,199,254,740,992 (25^3), inclusive.
18) What is a numeric literal in js?:-
numbers that appear directly in the js code.
19) What is the structure of a base 16 literal?:-
hexdecimal values start with a 0x or 0X, followed by a string of hexdecimal digints. hexdecimal values go from 0 - 9 and a/A - f/F (10 - 15)
examples
0xff // => 255: (15*16 + 15 * 16)
0xBADCAFE // => 195939070
20) ES6 introduces binary and octal interger representations as:-
-> base 2 (0b or 0B) 0b10101 // => 21: (116 + 08 + 14 + 02 + 11)
-> base 8 (0o or 0O) 0o377 // => 255: (364 + 78 + 71)
21) Arthimetics in javaScript does not raise errors in case of overflow, underflow and division by zero.
What definitions of js hand this three cases?:-
-> When the result of a numeric operation is larger than the largest repre‐ sentable number (overflow),
the result is a special infinity value, Infinity. Similarly, when the absolute value of a negative value becomes
larger than the absolute value of the largest representable negative number, the result is negative infinity, -Infinity.
* The infinite values behave as you would expect: adding, subtracting, multiplying,
or dividing them by anything results in an infinite value (possibly with the sign reversed).
-> Underflow occurs when the result of a numeric operation is closer to zero than the smallest representable number.
In this case, JavaScript returns 0. If underflow occurs from a negative number, JavaScript returns a special value known as “negative zero.”
-> Division by zero is not an error in JavaScript: it simply returns infinity or negative infinity. There is one exception,
however: zero divided by zero does not have a well- defined value, and the result of this operation is the special not-a-number value, NaN.
* JavaScript predefines global constants Infinity and NaN to hold the positive infinity and not-a-number value,
and these values are also available as properties of the Number object:
Infinity // A positive number too big to represent
Number.POSITIVE_INFINITY // Same value
1/0 // => Infinity or NaN
Number.MAX_VALUE * 2 // => Infinity; overflow
NOTE: adding a negtive sign in the example above gives negative infinity.
Number.MIN_VALUE/2 // => 0: underflow
-Number.MIN_VALUE/2 // => -0: negative zero
-1/Infinity // -> -0: also negative 0
-0
22) What does NaN stand for?:-
not-a-number
23) When does NaN(not-a-number) arise?:-
-> division by zero(can also return -Infinity(negative infinity)).
-> dividing Infinity by Infinity.
-> taking the square root of a negative number.
-> using arthimetic operations on non-numeric operands that cannot be coverted to numbers.
NaN // The not-a-number value
Number.NaN // The same value, written another way
0/0 // => NaN
Infinity/Infinity // => NaN
24) What is the unsual feature of the NaN value?:-
It does not compare equal to any other value, including itself.