JavaScript Fundamentals Flashcards

1
Q

What was JavaScript initially called?

A

LiveScript

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

What is the specification for JavaScript?

A

ECMAScript

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

True or False: JavaScript and Java are the same.

A

False

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

List three benefits of using JavaScript.

A
  • Full integration with HTML/CSS
  • Simple things are done simply
  • Support by all major browsers and enabled by default
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the primary task of a JavaScript engine?

A

To convert (compile) the JavaScript to machine-executable binaries.

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

What are two examples of JavaScript engines?

A
  • V8 (Chrome, Opera, Edge)
  • SpiderMonkey (Firefox)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the basic structure of JavaScript code?

A

JavaScript commands are written in statements separated by semicolons.

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

What are the keywords used to declare a variable in JavaScript?

A
  • const
  • var
  • let
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What characters are allowed in variable names?

A
  • Letters
  • Digits
  • Symbols $ and _
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the special value that represents nothing in JavaScript?

A

null

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

What does the Boolean type represent?

A

Two values: true and false.

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

What is the maximum safe integer value in JavaScript?

A

2**53 - 1 (9,007,199,254,740,991) - just over 9 quadrillion

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

Fill in the blank: In JavaScript, a _______ is a special value that indicates a variable has been declared but not assigned a value.

A

undefined

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

What is the syntax to create a string with embedded expressions?

A

Backticks (``)

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

True or False: All data types in JavaScript are considered primitive except for objects.

A

True

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

What operator is used to check the type of a variable?

A

typeof

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

What is the result of typeof null?

A

object

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

What is the purpose of the String class function in type conversion?

A

To explicitly convert other types to strings.

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

What happens during implicit numeric conversion in JavaScript?

A

Strings are automatically converted to numbers in mathematical operations.

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

List three values that convert to false in Boolean conversion.

A
  • ””
  • 0
  • null
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What does a variable declared but not assigned a value return when logged?

A

undefined

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

How can you create a BigInt in JavaScript?

A

By appending ‘n’ to an integer.

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

What is a key characteristic of JavaScript as a programming language?

A

JavaScript is a dynamically typed language.

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

What is the output of console.log(NaN ? ‘NaN is true’ : ‘NaN is false’)?

A

NaN is false

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

What is the output of console.log(0 ? ‘zero is true’ : ‘zero is false’)?

A

zero is false

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

What is the output of console.log(‘hello’ ? ‘hello is true’ : ‘hello is false’)?

A

hello is true

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

What does the negation operator (!) do?

A

Converts a value to boolean and then negates it

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

What is the output of console.log(!undefined)?

A

true

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

What is the output of console.log(!!”” )?

30
Q

How does JavaScript compare strings?

A

Using dictionary or lexicographical order

31
Q

What is the first step in comparing two strings?

A

Compare the first character of both strings

32
Q

If both strings have the same first character, what should be done next?

A

Compare the second characters the same way

33
Q

What is the output of console.log(‘apple’ < ‘banana’)?

34
Q

What happens when comparing different types using >, <, == and !=?

A

JavaScript converts the values to numbers

35
Q

What is the output of console.log(‘2’ > 1)?

36
Q

What does the ‘return’ keyword do in a function?

A

Sends a value back to where the function was called

37
Q

What is the syntax for a function declaration?

A

function functionName(parameters) { // function body }

38
Q

What is the purpose of the DRY principle in programming?

A

Avoiding repetition by defining code once and calling it multiple times

39
Q

What is the difference between function declaration and function expression?

A

Function declaration can be hoisted; function expression cannot be accessed before definition

40
Q

What is an arrow function?

A

A concise version of function expression using => syntax

41
Q

How do arrow functions differ from regular functions in terms of ‘arguments’?

A

Arrow functions cannot access the ‘arguments’ variable

42
Q

What is an object in JavaScript?

A

A complex variable that stores keyed collections of various data

43
Q

How can an object be created in JavaScript?

A

Using curly brackets {} or the Object constructor

44
Q

What is a property in an object?

A

A key:value pair where key is a string and value can be anything

45
Q

What happens when accessing a non-existing property of an object?

A

It returns undefined

46
Q

How can you iterate over all keys of an object?

A

Using a for … in loop

47
Q

What is the output of console.log(object) if object = { 2: ‘value of numeric property’, ‘2’: ‘value of string property’ }?

A

{ ‘2’: ‘value of string property’ }

48
Q

What is the difference between shallow copy and deep clone?

A

Shallow copy replicates the structure but not nested object properties; deep clone copies all levels

49
Q

What is a method in the context of an object?

A

A function that is a property of an object

50
Q

How can an object method access its own properties?

A

Using the ‘this’ keyword

51
Q

What keyword is used to access the information stored in an object within its methods?

52
Q

In the context of an object method, what does the value of ‘this’ refer to?

A

The object before the dot, the one used to call the method.

53
Q

What is the output of user.printGreeting() when user is defined as { name: ‘Bilbo Baggins’, printGreeting() { console.log(Hello, I'm ${this.name}) } }?

A

Hello, I’m Bilbo Baggins

54
Q

True or False: The value of ‘this’ in JavaScript is evaluated at compile-time.

55
Q

What allows methods to be chained together in JavaScript objects?

A

Returning ‘this’ from a method.

56
Q

What are the naming conventions for constructor functions in JavaScript?

A

Named with a capital letter first.

57
Q

What must be used to execute a constructor function?

A

The new operator.

58
Q

What is the first step when a function is executed with the ‘new’ keyword?

A

A new empty object is created and assigned to ‘this’.

59
Q

What is one difference between constructor functions and ES6 classes?

A

Classes have an explicit constructor function.

60
Q

Fill in the blank: In ES6, the new syntax keyword _______ is introduced for creating object blueprints.

61
Q

What does the hasShortName method return for a user with first name ‘Tim’?

62
Q

List three advantages of programming in JavaScript.

A
  • Event-driven
  • Asynchronous
  • High-level
63
Q

What are the three keywords used to create a variable in JavaScript?

A
  • var
  • let
  • const
64
Q

What are five common variable data types in JavaScript?

A
  • Number
  • String
  • Boolean
  • Object
  • Undefined
65
Q

What are the three types of quotes used to create a string in JavaScript?

A
  • Single quotes
  • Double quotes
  • Backticks
66
Q

What is the difference between null and undefined?

A

Null is an intentional absence of value; undefined means a variable has been declared but not assigned.

67
Q

How can we convert a variable to a string in JavaScript?

A

Using String() or .toString() method.

68
Q

How can we convert a variable to a number in JavaScript?

A

Using Number() or parseInt()/parseFloat() methods.

69
Q

What is a boolean?

A

A data type that can be either true or false.

70
Q

What are the three ways to create a function in JavaScript?

A
  • Function declaration
  • Function expression
  • Arrow function
71
Q

What is an object in JavaScript?

A

A collection of properties, each defined as a key-value pair.

72
Q

How can we create an object in JavaScript?

A

Using object literal syntax or constructor functions.