Podcast
Questions and Answers
What is a defining feature of variables declared with const?
What is a defining feature of variables declared with const?
How can a property of a JavaScript object be accessed?
How can a property of a JavaScript object be accessed?
What does the function toCelsius(fahrenheit) do?
What does the function toCelsius(fahrenheit) do?
Which of the following statements about JavaScript objects is false?
Which of the following statements about JavaScript objects is false?
Signup and view all the answers
What result does person.fullName() return?
What result does person.fullName() return?
Signup and view all the answers
What is true regarding HTML events?
What is true regarding HTML events?
Signup and view all the answers
Which method correctly calls an object method?
Which method correctly calls an object method?
Signup and view all the answers
Which of the following is NOT a characteristic of const variables?
Which of the following is NOT a characteristic of const variables?
Signup and view all the answers
In JavaScript, an object allows for the grouping of which of the following?
In JavaScript, an object allows for the grouping of which of the following?
Signup and view all the answers
To access the last name of a person stored in an object, which of the following syntaxes is correct?
To access the last name of a person stored in an object, which of the following syntaxes is correct?
Signup and view all the answers
What does the slice() method do when a second parameter is omitted?
What does the slice() method do when a second parameter is omitted?
Signup and view all the answers
What is the output of the code: let part = str.slice(-12); where str is 'Apple, Banana, Kiwi'?
What is the output of the code: let part = str.slice(-12); where str is 'Apple, Banana, Kiwi'?
Signup and view all the answers
How does substr() differ from slice() in terms of the second parameter?
How does substr() differ from slice() in terms of the second parameter?
Signup and view all the answers
What will the following code output: let part = str.substr(-4); where str is 'Apple, Banana, Kiwi'?
What will the following code output: let part = str.substr(-4); where str is 'Apple, Banana, Kiwi'?
Signup and view all the answers
What is a key characteristic of the replace() method?
What is a key characteristic of the replace() method?
Signup and view all the answers
If str is 'Apple, Banana, Kiwi', what will str.slice(7, 13) return?
If str is 'Apple, Banana, Kiwi', what will str.slice(7, 13) return?
Signup and view all the answers
What happens if the first parameter of slice() is negative?
What happens if the first parameter of slice() is negative?
Signup and view all the answers
What will be the output of the following code: let part = str.substr(7, 6); if str is 'Apple, Banana, Kiwi'?
What will be the output of the following code: let part = str.substr(7, 6); if str is 'Apple, Banana, Kiwi'?
Signup and view all the answers
What is the result of calling str.replace('a', 'o') on the string 'Apple, Banana, Kiwi'?
What is the result of calling str.replace('a', 'o') on the string 'Apple, Banana, Kiwi'?
Signup and view all the answers
What does the slice() method return if both parameters are negative, e.g., str.slice(-5, -1)?
What does the slice() method return if both parameters are negative, e.g., str.slice(-5, -1)?
Signup and view all the answers
What will be the output of the following code: let text = 'MSA students and MSA staff!'; let newText = text.replace('MSA', 'CS'); console.log(newText);?
What will be the output of the following code: let text = 'MSA students and MSA staff!'; let newText = text.replace('MSA', 'CS'); console.log(newText);?
Signup and view all the answers
Which of the following statements correctly uses the concat() method?
Which of the following statements correctly uses the concat() method?
Signup and view all the answers
What does the toUpperCase() method do?
What does the toUpperCase() method do?
Signup and view all the answers
What is the purpose of the trim() method in string manipulation?
What is the purpose of the trim() method in string manipulation?
Signup and view all the answers
In which scenario would you use the split() method?
In which scenario would you use the split() method?
Signup and view all the answers
How would you correctly call the toLowerCase() method on a string variable text1?
How would you correctly call the toLowerCase() method on a string variable text1?
Signup and view all the answers
What does the output of the following code produce: let text1 = ' welcome!'; let text2 = text1.trim(); console.log(text2);?
What does the output of the following code produce: let text1 = ' welcome!'; let text2 = text1.trim(); console.log(text2);?
Signup and view all the answers
What is expected when using the split() method with a pipe character as the delimiter, given the string 'a|b|c|d|e|f'?
What is expected when using the split() method with a pipe character as the delimiter, given the string 'a|b|c|d|e|f'?
Signup and view all the answers
Which method would you use to remove whitespace only from the start of a string?
Which method would you use to remove whitespace only from the start of a string?
Signup and view all the answers
If the below code is executed, what will be the value of myArray? let text = 'a b c d e f'; const myArray = text.split(' ');
If the below code is executed, what will be the value of myArray? let text = 'a b c d e f'; const myArray = text.split(' ');
Signup and view all the answers
What does the 'onchange' event signify in HTML?
What does the 'onchange' event signify in HTML?
Signup and view all the answers
Which of the following is NOT a valid HTML event?
Which of the following is NOT a valid HTML event?
Signup and view all the answers
Which method is used to determine the length of a string in JavaScript?
Which method is used to determine the length of a string in JavaScript?
Signup and view all the answers
What does the 'substr(start, length)' function do in JavaScript?
What does the 'substr(start, length)' function do in JavaScript?
Signup and view all the answers
What will the following code return: let text = 'Hello'; text[1];
?
What will the following code return: let text = 'Hello'; text[1];
?
Signup and view all the answers
Which of the following correctly uses template literals for variable substitution?
Which of the following correctly uses template literals for variable substitution?
Signup and view all the answers
Which event should you use to execute a function after a page has finished loading?
Which event should you use to execute a function after a page has finished loading?
Signup and view all the answers
What will the output of the following code be: let greeting = 'Hello World'; console.log(greeting.slice(0, 5));
?
What will the output of the following code be: let greeting = 'Hello World'; console.log(greeting.slice(0, 5));
?
Signup and view all the answers
Which string declaration is correct in JavaScript?
Which string declaration is correct in JavaScript?
Signup and view all the answers
Study Notes
JavaScript - Introduction - II
- Constant Variables: Constants cannot be re-declared or reassigned. They have block scope.
- Functions in JavaScript: A function is a block of code used for a particular task. It is executed when called or invoked. Functions can accept parameters.
- JavaScript Objects: A JavaScript object is a versatile collection of key-value pairs (properties) and actions (methods). You use objects to group related data and behaviors. Objects are variables that have properties and functions.
- Retrieving Object Properties: Accessing an object's property can be done in two ways: objectName["propertyName"] or objectName.propertyName
HTML Events
- HTML Events: Events can be actions resulting from a user or happening within the browser, such as page loading, user clicks, mouse movements, form input changes, and button clicks. Specific JavaScript code is often associated with these events.
Strings in JavaScript
- String Definition: Strings in JavaScript can use single or double quotes.
- Quotes within Strings: Nested quotes are possible as long as the enclosing quotes differ in style.
- Escape Characters: Special characters like apostrophes or backslashes can be included, using "".
-
String Properties and Methods: JavaScript strings have properties such as
.length
and methods for various operations like.slice()
,.substring()
,.substr()
,.replace()
,.concat()
,.toUpperCase()
,.toLowerCase()
,.trim()
,.trimStart()
,.trimEnd()
,.split()
String Functions
- slice(start, end): A string function that extracts a portion of the string. If the end parameter is omitted, the rest of the string is extracted. The extracted string does not include the character at the end position
- substring(start, end): Extracts a portion of a string from one index to another. It treats negative values as zero and does not include the final index
-
substr(start, length): Extracts characters starting at
start
for a specificlength
.
Variable Substitutions
- Variable substitutions in strings use template literals (
\
${expression}``) to substitute variables directly - String concatenation can use the
concat()
method or a plus (+
) operator
Additional notes
- The example code for various JavaScript string functions has been omitted but is readily accessible via the example links given.
- The presentation contained various examples of these JavaScript concepts.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
This quiz explores advanced concepts in JavaScript, including constant variables, functions, and objects. You'll learn how to retrieve object properties and understand HTML events alongside string handling in JavaScript. Dive deeper into the fundamentals of programming with this engaging assessment.