Basic JS Flashcards

1
Q

What is the difference between
Loose equality (==and !=)
Strict equality (=== and !==)
Give examples of each.

A

Both are used for comparison between two variables:

Loose equality:
== compares whilst ignoring the Type of variable (checks for value) - AVOID - produces unexpected results.
e.g.  5=="5" (true)
"" == "0" (false)
0 == "" (true)

Strict equality:
=== compares whilse checking the datatype AND comparing the two values.
(checks for value + type)
e.g. 5===”5” (false)

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

What is the “Unary +” Operator? e.g. +hello

A

It attempts to convert to a number. +v is the same as Number(v)

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

”$” + 4 + 5 =

A

“$45”

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

” \t \n” - 2 =

A

-2

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

Whats the difference between NULL and Undefined?
When are they used?
What is the typeOf null and typeOf undefined

A
NULL = Non existing | Null pointe
Null us a separate type of it's own that contains only the null value.
Javascript never sets a value to null by default.
typeof === Object (this is a very old JS bug that was decided to be left in)
let myVariable = null;

Undefined = Value declared but not assigned a value
typeof === undefined
let myVariable;

Usually use null to assign empty or unknown values and undefined for checks to see whether a variable has been assigned.

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

What are the eight data types of javascript?

A
  • number -for numbers of any kind: integer or floating-point, integers are limited by±(2531).
  • bigint -is for integer numbers of arbitrary length.
  • string - for strings. A string may have zero or more characters, there’s no separate single-character type.
  • boolean -fortrue/false.
  • nullfor unknown values – a standalone type that has a single valuenull.
  • undefinedfor unassigned values – a standalone type that has a single valueundefined.
  • objectfor more complex data structures.
  • symbolfor unique identifiers.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a primitive data type, which data type is NOT primitive?

A

“primitive” values can contain only a single thing (be it a string or a number or whatever)

Objects - are NOT primitive they are used to store collections of data and more complex entities.

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

What is the difference between substring/substr/slice. Which one is considered a “legacy function”?

A

All of them returns the portion of the string that starts at indexStart and ends the character immediately preceding indexEnd (DOES NOT RETURN THE LAST ONE, RETURNS THE ONE BEFORE IT)

str.substring(indexStart, indexEnd);
If indexStart or indexEnd is less than 0, it is treated as 0.
If indexEnd < indexStart, the two are swapped.

substr () - legacy, don't use in new code.
substr is considered a "legacy function" in Mozilla's docs. You shouldn't use it when writing new code.
Unlike substring(), you can call substr() with a negative start

str.slice(beginIndex, endIndex)
Best of both worlds between slice and substring
-Supports negative indices

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

What are the three logical operators and what do they stand for?

A

|| && !

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

What are truthy and falsy values? and What are the 6 falsy values in JavaScript?

A

truthy || falsy values are values that is considered true or false when encountered in a Boolean context.

6 falsy values = ‘Empty Quotes’ 0 NaN undefined null false

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

What are the two ways to convert a value to a boolean?

A

!! and Boolean()

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

Is Javascript Statically Typed, or Dynamically typed? What do they mean?

A

JS is Dynamically typed: a variable can change from one type to another. Not statically typed like “int number = 5”

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

What are the types of Exports? How are they exported and imported?

A
Named Exports (0 or more exports per module)
Named exports are exported as an object, so they are DESTRUCTURED ON IMPORT.
export const arrayOne = [1,2,3]
export const arrayTwo = [4,5,6]
import {arrayOne, arrayTwo} from "./locationWherever"

Default Exports (1 export per module)

const arrayOne = [1,2,3]
export default arrayOne;
import arrayOne from "./locationWherever"
How well did you know this?
1
Not at all
2
3
4
5
Perfectly