Podcast
Questions and Answers
Which keyword is used to declare variables in JavaScript?
Which keyword is used to declare variables in JavaScript?
What method is used to find the largest value between two numbers in JavaScript?
What method is used to find the largest value between two numbers in JavaScript?
Which of the following data types is not valid in JavaScript?
Which of the following data types is not valid in JavaScript?
What is the result of '5 + 4 + (2 * 3)' in JavaScript?
What is the result of '5 + 4 + (2 * 3)' in JavaScript?
Signup and view all the answers
What comment syntax is used in JavaScript similar to Java?
What comment syntax is used in JavaScript similar to Java?
Signup and view all the answers
If a variable has not been declared and does not exist, what value does it hold in JavaScript?
If a variable has not been declared and does not exist, what value does it hold in JavaScript?
Signup and view all the answers
What does document.getElementById return in JavaScript?
What does document.getElementById return in JavaScript?
Signup and view all the answers
How can you change the text inside most elements in the DOM using JavaScript?
How can you change the text inside most elements in the DOM using JavaScript?
Signup and view all the answers
In JavaScript, what property can be set to change the text in form controls like textboxes?
In JavaScript, what property can be set to change the text in form controls like textboxes?
Signup and view all the answers
What does the function changeText() in JavaScript do?
What does the function changeText() in JavaScript do?
Signup and view all the answers
Which method allows you to manipulate or initialize text in JavaScript?
Which method allows you to manipulate or initialize text in JavaScript?
Signup and view all the answers
Which CSS style property is NOT changed in the function Preetify() in JavaScript?
Which CSS style property is NOT changed in the function Preetify() in JavaScript?
Signup and view all the answers
What type of programming is JavaScript known for?
What type of programming is JavaScript known for?
Signup and view all the answers
In JavaScript, what is used to write a JavaScript function that will run when an event occurs?
In JavaScript, what is used to write a JavaScript function that will run when an event occurs?
Signup and view all the answers
What is an example of an event attribute commonly used in HTML?
What is an example of an event attribute commonly used in HTML?
Signup and view all the answers
How can a JavaScript function be invoked in response to a user's click on an element?
How can a JavaScript function be invoked in response to a user's click on an element?
Signup and view all the answers
What is a common drawback associated with using alert windows in JavaScript?
What is a common drawback associated with using alert windows in JavaScript?
Signup and view all the answers
Which HTML attribute is used to set a JavaScript function as an event handler for element interactions?
Which HTML attribute is used to set a JavaScript function as an event handler for element interactions?
Signup and view all the answers
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
andPI
. - 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.
Description
Test your knowledge on JavaScript variables and types syntax by answering questions related to declaring variables, assigning values, and understanding data types in JavaScript. Explore concepts like loosely typed nature, types such as Number, Boolean, String, Array, Object, Function, Null, and Undefined, and identifying variable types using 'typeof'.