JavaScript Fundamentals Flashcards
What was JavaScript initially called?
LiveScript
What is the specification for JavaScript?
ECMAScript
True or False: JavaScript and Java are the same.
False
List three benefits of using JavaScript.
- Full integration with HTML/CSS
- Simple things are done simply
- Support by all major browsers and enabled by default
What is the primary task of a JavaScript engine?
To convert (compile) the JavaScript to machine-executable binaries.
What are two examples of JavaScript engines?
- V8 (Chrome, Opera, Edge)
- SpiderMonkey (Firefox)
What is the basic structure of JavaScript code?
JavaScript commands are written in statements separated by semicolons.
What are the keywords used to declare a variable in JavaScript?
- const
- var
- let
What characters are allowed in variable names?
- Letters
- Digits
- Symbols $ and _
What is the special value that represents nothing in JavaScript?
null
What does the Boolean type represent?
Two values: true and false.
What is the maximum safe integer value in JavaScript?
2**53 - 1 (9,007,199,254,740,991) - just over 9 quadrillion
Fill in the blank: In JavaScript, a _______ is a special value that indicates a variable has been declared but not assigned a value.
undefined
What is the syntax to create a string with embedded expressions?
Backticks (``)
True or False: All data types in JavaScript are considered primitive except for objects.
True
What operator is used to check the type of a variable?
typeof
What is the result of typeof null?
object
What is the purpose of the String class function in type conversion?
To explicitly convert other types to strings.
What happens during implicit numeric conversion in JavaScript?
Strings are automatically converted to numbers in mathematical operations.
List three values that convert to false in Boolean conversion.
- ””
- 0
- null
What does a variable declared but not assigned a value return when logged?
undefined
How can you create a BigInt in JavaScript?
By appending ‘n’ to an integer.
What is a key characteristic of JavaScript as a programming language?
JavaScript is a dynamically typed language.
What is the output of console.log(NaN ? ‘NaN is true’ : ‘NaN is false’)?
NaN is false
What is the output of console.log(0 ? ‘zero is true’ : ‘zero is false’)?
zero is false
What is the output of console.log(‘hello’ ? ‘hello is true’ : ‘hello is false’)?
hello is true
What does the negation operator (!) do?
Converts a value to boolean and then negates it
What is the output of console.log(!undefined)?
true
What is the output of console.log(!!”” )?
false
How does JavaScript compare strings?
Using dictionary or lexicographical order
What is the first step in comparing two strings?
Compare the first character of both strings
If both strings have the same first character, what should be done next?
Compare the second characters the same way
What is the output of console.log(‘apple’ < ‘banana’)?
true
What happens when comparing different types using >, <, == and !=?
JavaScript converts the values to numbers
What is the output of console.log(‘2’ > 1)?
true
What does the ‘return’ keyword do in a function?
Sends a value back to where the function was called
What is the syntax for a function declaration?
function functionName(parameters) { // function body }
What is the purpose of the DRY principle in programming?
Avoiding repetition by defining code once and calling it multiple times
What is the difference between function declaration and function expression?
Function declaration can be hoisted; function expression cannot be accessed before definition
What is an arrow function?
A concise version of function expression using => syntax
How do arrow functions differ from regular functions in terms of ‘arguments’?
Arrow functions cannot access the ‘arguments’ variable
What is an object in JavaScript?
A complex variable that stores keyed collections of various data
How can an object be created in JavaScript?
Using curly brackets {} or the Object constructor
What is a property in an object?
A key:value pair where key is a string and value can be anything
What happens when accessing a non-existing property of an object?
It returns undefined
How can you iterate over all keys of an object?
Using a for … in loop
What is the output of console.log(object) if object = { 2: ‘value of numeric property’, ‘2’: ‘value of string property’ }?
{ ‘2’: ‘value of string property’ }
What is the difference between shallow copy and deep clone?
Shallow copy replicates the structure but not nested object properties; deep clone copies all levels
What is a method in the context of an object?
A function that is a property of an object
How can an object method access its own properties?
Using the ‘this’ keyword
What keyword is used to access the information stored in an object within its methods?
this
In the context of an object method, what does the value of ‘this’ refer to?
The object before the dot, the one used to call the method.
What is the output of user.printGreeting() when user is defined as { name: ‘Bilbo Baggins’, printGreeting() { console.log(Hello, I'm ${this.name}
) } }?
Hello, I’m Bilbo Baggins
True or False: The value of ‘this’ in JavaScript is evaluated at compile-time.
False
What allows methods to be chained together in JavaScript objects?
Returning ‘this’ from a method.
What are the naming conventions for constructor functions in JavaScript?
Named with a capital letter first.
What must be used to execute a constructor function?
The new operator.
What is the first step when a function is executed with the ‘new’ keyword?
A new empty object is created and assigned to ‘this’.
What is one difference between constructor functions and ES6 classes?
Classes have an explicit constructor function.
Fill in the blank: In ES6, the new syntax keyword _______ is introduced for creating object blueprints.
class
What does the hasShortName method return for a user with first name ‘Tim’?
true
List three advantages of programming in JavaScript.
- Event-driven
- Asynchronous
- High-level
What are the three keywords used to create a variable in JavaScript?
- var
- let
- const
What are five common variable data types in JavaScript?
- Number
- String
- Boolean
- Object
- Undefined
What are the three types of quotes used to create a string in JavaScript?
- Single quotes
- Double quotes
- Backticks
What is the difference between null and undefined?
Null is an intentional absence of value; undefined means a variable has been declared but not assigned.
How can we convert a variable to a string in JavaScript?
Using String() or .toString() method.
How can we convert a variable to a number in JavaScript?
Using Number() or parseInt()/parseFloat() methods.
What is a boolean?
A data type that can be either true or false.
What are the three ways to create a function in JavaScript?
- Function declaration
- Function expression
- Arrow function
What is an object in JavaScript?
A collection of properties, each defined as a key-value pair.
How can we create an object in JavaScript?
Using object literal syntax or constructor functions.