Basic Concepts Flashcards

1
Q

JavaScript is defined as…

A

A lightweight, multi-paradigm, single-threaded, dynamic scripting language that is found in all modern web technologies

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

The main 8 types of the JavaScript language

A

1) Number
2) BigInt
3) String
4) Boolean
5) Object
6) Null
7) Undefined
8) Symbol

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

How is the Number type implemented

A

As a double-precision 64-bit binary format IEEE 754 value

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

What are some subclasses of Objects available to you in JavaScript

A
  • Function
  • Array
  • Date
  • RegExp
  • Math
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

parseInt()

A

this will parse a string into an integer value, where the first parameter is the string, and the second is the base you want to parse out.

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

NaN

A

This means ‘Not a Number’, and is the result of trying to use a non-number value in a number context.
i.e. parseInt(‘hello’, 10);

use Number.isNaN(value) to check for NaNness

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

NaN is ‘toxic’

A

Any mathematical operation with a NaN, will result in NaN

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

parseFloat()

A

Similar to parseInt, but only uses base 10 and will output the floating point representation of the value parsed.

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

Falsy Values

A

False, 0, “”, NaN, null, undefined

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

Truthy Values

A

Anything that is not Falsy

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

let vs. const. vs. var

A

let: declares a mutable variable in block scope
const: declares an immutable variable in block scope
var: declares a mutable variable with global scope (DONT USE)

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

for…in vs. for…of

A

for in is used to iterate over enumerable values. It is good for checking the existence of keys in a map/object. does not guarantee order of enumeration.
for of is useful for iteration of iterable values, so arrays, strings, etc. more often than not, this will be the preferred one.

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

x && x.name

A

as long as x exists, return x.name

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

x.name || x.getName()

A

if x.name doesn’t exist, get it

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

A variable can start with

A

Any letter along with $ and _

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

??

A

Nullish Coalescence Operator
a ?? b
if ‘a’ is null/undefined then ‘b’, otherwise ‘a’

17
Q

== vs. ===

A

Equality vs. Strict Equality
== : this will attempt to convert the types of the value on each side of the equals sign into the same type before comparing.
===: this will do no such comparison and will strictly compare the two values for equality

18
Q

comma operator

A

evaluates everything in the expression, from left to right, and returns the final expression evaluated. (the rightmost value after the final comma)

19
Q

function (x = 1, x = 2) {}

A

Functions can be given default parameters, this allows for default values to be used in the event that none are passed in

20
Q

Transpilers

A

Special piece of software that translates one source code into another. Main difference between this and a compiler, is there is no speed/performance improvement intended. It would be like translating python into ruby.

ex. of transpilers
Babel

21
Q

Polyfills

A

Basically a pollyfill is a function that exists because the actual function you are using is not supported yet in some browsers.

This is a consequence of the language being updated without full support for its updates. So certain functions don’t actually have any meaning in older browsers (ex. Math.trunc()) and have to be substituted with a “fill”

22
Q

?.

A

Optional Chaining
Allows you to safely access nested values of an object, even if they, or the object, or a subcall doesn’t exist

it will return undefined in the case where something along the chain does not exist, rather than throwing an error

can also use ?.() for optional method calls and ?.[] for optional array access

23
Q

Symbols

A

Guaranteed to be Unique

They are a new addition to the language

24
Q

“use strict”

A

Places the execution environment into strict mode.
Makes it easier to write secure JavaScript
This essentially does 3 things
1) Eliminates some JS silent errors by changing them to throw errors
2) Fixes mistakes that make it difficult for JS engines to make optimizations
3) Prohibits some syntax from being used

25
Q

toFixed(number)

A

A number method that rounds to a fixed decimal place and returns it as a string

26
Q

Number, String, Boolean wrappers

A

These are wrappers that will covert the value passed in into the type of the wrapper. Using new will create an object, but without new, it is just a cast essentially.

27
Q

1_000_000

A

The underscore is a valid separator for numbers and will be parsed as if they were not there

28
Q

Math. floor, ceil, round, trunc

A

floor: rounds down
ceil: rounds up
round: rounds to nearest integer
trunc: removes anything after the decimal (no rounding)

29
Q

isFinite(value), isNaN(value)

A

Infinity and Nan checks

30
Q

Object.is(a,b)

A

This is another way to use ===