JavaScript Variables and Types Syntax Quiz

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 keyword is used to declare variables in JavaScript?

  • var (correct)
  • int
  • const
  • let

What method is used to find the largest value between two numbers in JavaScript?

  • round
  • max (correct)
  • abs
  • min

Which of the following data types is not valid in JavaScript?

  • Double (correct)
  • Null
  • Function
  • Array

What is the result of '5 + 4 + (2 * 3)' in JavaScript?

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

What comment syntax is used in JavaScript similar to Java?

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

If a variable has not been declared and does not exist, what value does it hold in JavaScript?

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

What does document.getElementById return in JavaScript?

<p>The DOM object for an element with a given id (A)</p> Signup and view all the answers

How can you change the text inside most elements in the DOM using JavaScript?

<p>By setting the innerHTML property (D)</p> Signup and view all the answers

In JavaScript, what property can be set to change the text in form controls like textboxes?

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

What does the function changeText() in JavaScript do?

<p>Change the style of a textbox (D)</p> Signup and view all the answers

Which method allows you to manipulate or initialize text in JavaScript?

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

Which CSS style property is NOT changed in the function Preetify() in JavaScript?

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

What type of programming is JavaScript known for?

<p>Event-driven programming (A)</p> Signup and view all the answers

In JavaScript, what is used to write a JavaScript function that will run when an event occurs?

<p>JavaScript event handler (D)</p> Signup and view all the answers

What is an example of an event attribute commonly used in HTML?

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

How can a JavaScript function be invoked in response to a user's click on an element?

<p><code>onclick</code> attribute (D)</p> Signup and view all the answers

What is a common drawback associated with using alert windows in JavaScript?

<p>They disrupt the user experience (C)</p> Signup and view all the answers

Which HTML attribute is used to set a JavaScript function as an event handler for element interactions?

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

Flashcards are hidden until you start studying

Study Notes

Variables

  • In JavaScript, variables are declared using the var keyword.
  • Variable types are not specified, but JavaScript has types including Number, Boolean, String, Array, Object, Function, Null, and Undefined.
  • The typeof operator can be used to find out a variable's type.

Number Type

  • Integers and real numbers are the same type in JavaScript.
  • Same operators are used for numbers: +, -, *, /, %, ++, --, =, +=, -=, *=, /=, %=.
  • Many operators auto-convert types, e.g., "2" * 3 is 6.

Comments

  • JavaScript comments are the same as Java comments.
  • There are four comment syntaxes: HTML, CSS/JS/PHP, Java/JS/PHP, and PHP.

Math Object

  • The Math object has methods: abs, ceil, cos, floor, log, max, min, pow, random, round, sin, sqrt, tan.
  • The Math object has properties: E and PI.
  • Examples: var rand1to10 = Math.floor(Math.random() * 10 + 1);, var three = Math.floor(Math.PI);.

Null and Undefined

  • null exists, but was specifically assigned an empty or null value.
  • undefined has not been declared, does not exist.

Document Object Model (DOM)

  • Most JavaScript code manipulates elements on an HTML page.
  • We can examine elements' state and change state.
  • Examples: see whether a box is checked, insert new text into a div, change styles.

Accessing Elements

  • document.getElementById returns the DOM object for an element with a given id.
  • We can change the text inside most elements by setting the innerHTML property.
  • We can change the text in form controls by setting the value property.

Functions

  • A function is a block of code that can be called multiple times from different parts of the script.
  • Example: function changeText() { ... }.
  • Functions can be used as event handlers.

Event-Driven Programming

  • JavaScript programs wait for user actions called events and respond to them.
  • This is called event-driven programming.
  • Example: a clickable button that pops up a "Hello, World" window.

Studying That Suits You

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

Quiz Team
Use Quizgecko on...
Browser
Browser