JavaScript Primitives vs. Objects
10 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What method in JavaScript rounds a number to a given precision?

  • toFixed(n) (correct)
  • roundPrecision(n)
  • precisionRound(n)
  • numberRound(n)

Which constructor in JavaScript is considered highly unrecommended for creating wrapper objects?

  • new String()
  • new Boolean()
  • new Object()
  • new Number() (correct)

What is the output from the alert( typeof new Number(0) ) statement in JavaScript?

  • "string"
  • "boolean"
  • "number"
  • "object" (correct)

Why does the alert( 'zero is truthy!?!' ) statement get executed in the given code snippet?

<p>Because zero is treated as truthy since it's an object (A)</p> Signup and view all the answers

Which function in JavaScript converts a string into a number?

<p>Number() (D)</p> Signup and view all the answers

What is a key distinction between primitives and objects in JavaScript?

<p>Primitives are lightweight while objects are heavier and require additional resources. (B)</p> Signup and view all the answers

Which of the following is NOT a primitive type with its corresponding object wrapper?

<p>BigInt - BigNum (A)</p> Signup and view all the answers

What is a benefit of using objects in JavaScript?

<p>Objects provide a way to store functions as properties. (A)</p> Signup and view all the answers

Why does the creator of JavaScript use 'object wrappers' for primitives like String, Number, Boolean, Symbol, and BigInt?

<p>To provide different sets of methods for each primitive type. (B)</p> Signup and view all the answers

How does the JavaScript engine handle primitives when providing methods like str.toUpperCase()?

<p>Optimizes the process by possibly skipping the creation of an extra object. (A)</p> Signup and view all the answers

More Like This

JavaScript Class Definition
12 questions
JavaScript Non-Primitive Data Types
10 questions
Non-primitive Data Types in JavaScript
10 questions
Primitive Data Types in JavaScript
5 questions
Use Quizgecko on...
Browser
Browser