1 JavaScript Data Types Quiz
32 Questions
2 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

Which of the following correctly represents the string type in JavaScript?

  • Backticks: 'Hello'. (correct)
  • Single quotes: 'Hello'. (correct)
  • Floating quotes: 'Hello'.
  • Double quotes: 'Hello'. (correct)

What does the value 'null' represent in JavaScript?

  • A boolean false value.
  • A special value representing 'nothing'. (correct)
  • An undeclared variable.
  • An empty string.

What indicates that a variable has not been assigned a value?

  • null
  • undefined (correct)
  • NaN
  • 0

What will the expression '11 > 7' return in JavaScript?

<p>true (C)</p> Signup and view all the answers

What is the output of 'typeof null' in JavaScript?

<p>object (A)</p> Signup and view all the answers

Which statement regarding the number type in JavaScript is true?

<p>It can represent both integer and floating-point numbers. (D)</p> Signup and view all the answers

Which of the following values is considered NaN (Not a Number) in JavaScript?

<p>alert('not a number' / 2 + 5) (C)</p> Signup and view all the answers

Which statement about booleans in JavaScript is correct?

<p>They can only hold values true or false. (A)</p> Signup and view all the answers

What is a primary characteristic that differentiates JavaScript from Java?

<p>JavaScript is a scripting language created for web development. (B)</p> Signup and view all the answers

Which ECMAScript version was abandoned?

<p>ES4 (C)</p> Signup and view all the answers

How can JavaScript programs be embedded in an HTML document?

<p>Using the script tag anywhere within the HTML document. (C)</p> Signup and view all the answers

What is the role of the Math object in JavaScript?

<p>It provides mathematical constants and functions. (D)</p> Signup and view all the answers

Which of the following statements about JavaScript syntax is correct?

<p>Statements can be separated with semicolons. (A)</p> Signup and view all the answers

What is a primary use of the JavaScript DOM?

<p>To manipulate and interact with HTML content. (A)</p> Signup and view all the answers

Which of the following best describes the use of the 'alert' function in JavaScript?

<p>It displays a message in a dialog box and pauses execution. (A)</p> Signup and view all the answers

In what scenario would you typically use local storage in JavaScript?

<p>To remember user preferences on the client side. (C)</p> Signup and view all the answers

Which statement best describes the purpose of a variable in JavaScript?

<p>A variable is a named storage for data. (A)</p> Signup and view all the answers

Which declaration is considered correct for multiple variables in one line?

<p>let user = 'John', age = 25; (C)</p> Signup and view all the answers

What is the purpose of the const keyword in variable declaration?

<p>To declare a variable that cannot be changed. (B)</p> Signup and view all the answers

Which of the following is NOT a valid variable name in JavaScript?

<p>1stVariable (A)</p> Signup and view all the answers

What will be the result of the following operation: let a = 10; a += 5;?

<p>15 (B)</p> Signup and view all the answers

What does the expression '8 % 3' evaluate to?

<p>2 (A)</p> Signup and view all the answers

Which of the following describes the camelCase naming convention in JavaScript variables?

<p>The first word is in lowercase followed by words starting with capital letters. (C)</p> Signup and view all the answers

In JavaScript, what does the command 'alert(5 % 2)' produce?

<p>1 (C)</p> Signup and view all the answers

What does the expression 'a % b' return?

<p>The remainder of the integer division of a by b. (A)</p> Signup and view all the answers

Which operation is NOT a unary operation?

<p>a + b (C)</p> Signup and view all the answers

Which of the following methods returns a pseudorandom number?

<p>Math.random() (A)</p> Signup and view all the answers

In prefix notation, how would you increment the variable 'a' by 1?

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

Which statement is TRUE about JavaScript primitive data types?

<p>Boolean is a primitive data type. (B)</p> Signup and view all the answers

Which operation is an example of a binary operation?

<p>a &amp;&amp; b (A)</p> Signup and view all the answers

How can you retrieve the absolute value of a number 'x' in JavaScript?

<p>Math.abs(x) (B)</p> Signup and view all the answers

What will the following code output: console.log('a = ' + 5); ?

<p>'a = 5' (C)</p> Signup and view all the answers

Flashcards

String type in JavaScript

Represented using backticks or single/double quotes; stores text values.

null in JavaScript

A special value meaning 'nothing' or absence of a value.

undefined variable

A variable that has not been assigned any value.

11 > 7 in JavaScript

Returns true because 11 is greater than 7.

Signup and view all the flashcards

typeof null

Returns 'object' in JavaScript, a historical quirk.

Signup and view all the flashcards

Number type in JavaScript

Stores both integers and decimals.

Signup and view all the flashcards

NaN in JavaScript

Not a Number, representing invalid numerical results.

Signup and view all the flashcards

Boolean in JavaScript

Can only hold true or false.

Signup and view all the flashcards

JavaScript vs. Java

JavaScript is a scripting language for web development, while Java is a general-purpose language.

Signup and view all the flashcards

Abandoned ECMAScript version

ES4 was not finalized.

Signup and view all the flashcards

Embedding JavaScript in HTML

Use the <script> tag within the HTML.

Signup and view all the flashcards

Math object in JavaScript

Provides mathematical functions and constants.

Signup and view all the flashcards

JavaScript statement separators

Use semicolons to separate statements in JavaScript.

Signup and view all the flashcards

JavaScript DOM purpose

Used to manipulate HTML content.

Signup and view all the flashcards

alert function in JavaScript

Displays a message box and pauses execution.

Signup and view all the flashcards

Local storage in JavaScript

Used to store user preferences on the client side.

Signup and view all the flashcards

JavaScript variable

Named storage for data.

Signup and view all the flashcards

Multiple variable declaration in one line

Use commas to separate variables in a single declaration

Signup and view all the flashcards

const keyword in JavaScript

Declares a constant variable whose value cannot be changed.

Signup and view all the flashcards

Invalid variable name

'1stVariable' is invalid; variable names cannot start with numbers.

Signup and view all the flashcards

a += 5 operation

Adds 5 to the value of 'a'.

Signup and view all the flashcards

8 % 3 operation

Calculates the remainder of 8 divided by 3.

Signup and view all the flashcards

camelCase in variables

First word lowercase, subsequent words capitalized.

Signup and view all the flashcards

5 % 2 operation

Returns the remainder (1) when 5 is divided by 2.

Signup and view all the flashcards

a % b

Returns the integer remainder after dividing 'a' by 'b'.

Signup and view all the flashcards

Non-unary operation

An operation involving two operands (e.g., addition).

Signup and view all the flashcards

Math.random()

Generates a random number between 0 (inclusive) and 1 (exclusive).

Signup and view all the flashcards

Prefix increment ++a

Increases the value of 'a' by 1 and uses the new value.

Signup and view all the flashcards

JavaScript primitive data types

Basic data types like numbers, strings, boolean, null.

Signup and view all the flashcards

Binary operation example

A logical operation such as a && b

Signup and view all the flashcards

Math.abs(x)

Returns the absolute value of the number x.

Signup and view all the flashcards

console.log('a = ' + 5)

Displays the string 'a = 5' in the console.

Signup and view all the flashcards

Study Notes

JavaScript Data Types

  • JavaScript has three types of quotes:
    • Double quotes: "Hello"
    • Single quotes: 'Hello'
    • Backticks: Hello

Number

  • Number type represents both integers and floating point numbers
  • Special numeric values include:
    • Infinity: alert( 1 / 0 )
    • NaN (Not a Number): alert( "not a number" / 2 + 5 )

Boolean

  • Represents logical type with two values: true and false
  • Used for yes/no values, true represents "yes" and false "no"
  • true is assigned to nameFieldChecked when the field is checked
  • false is assigned to ageFieldChecked when the field is not checked

Null

  • null is a special value representing "nothing", "empty" or "value unknown"

Undefined

  • undefined indicates a value has not been assigned
  • If a variable is declared but not assigned, its value will be undefined

typeof Operator

  • The typeof operator returns the type of the argument
  • Two forms of syntax:
    • As an operator: typeof x
    • In parentheses: (typeof x)

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

JavaScript Fundamentals PDF

Description

Test your knowledge of JavaScript data types including strings, numbers, booleans, null, and undefined. This quiz will help reinforce your understanding of how these data types work and their specific uses in JavaScript programming.

More Like This

Tipovi Podataka u JavaScript-u
12 questions

Tipovi Podataka u JavaScript-u

BeneficialSanAntonio7072 avatar
BeneficialSanAntonio7072
JavaScript Tipovi
5 questions

JavaScript Tipovi

BeneficialSanAntonio7072 avatar
BeneficialSanAntonio7072
Primitive Data Types in JavaScript
5 questions
JavaScript Data Types Quiz
5 questions

JavaScript Data Types Quiz

SpontaneousThermodynamics9380 avatar
SpontaneousThermodynamics9380
Use Quizgecko on...
Browser
Browser