JavaScript NOTES
JavaScript NOTES
JavaScript NOTES
What is JavaScript?
JavaScript is a scripting language used to create and control dynamic website content.
setInterval()
The setInterval() method calls a function at specified intervals (in milliseconds).
The setInterval() method continues calling the function until clearInterval() is called, or the
window is closed.
1 second = 1000 millisecond
Note :
To execute the function only once, use the setTimeout() method instead.
• To clear an interval, use the id returned from setInterval():
var myInterval = setInterval(function, milliseconds);
• Then you can to stop the execution by calling clearInterval():
clearInterval(myInterval);
innerHTML Property in JS
innerHTML is an HTML element property that has two uses :
1) You can use it to get the internal HTML content of any HTML element as an HTML string.
2) You can also use it to set or change elements’ innerHTML content.
Example : document.getElementById(“z”).innerHTML=”Total Marks”+t;
JavaScript Operators
JavaScript operators are used to perform different types of mathematical and logical computations.
JavaScript
Examples:
The Assignment Operator = assigns values
The Addition Operator + adds values
The Multiplication Operator * multiplies values
The Comparison Operator > compares values
Types of JavaScript Operators
There are different types of JavaScript operators:
• Arithmetic Operators
• Assignment Operators
• Comparison Operators
• String Operators
• Logical Operators
• Bitwise Operators
• Ternary Operators
• Type Operators
JavaScript Arithmetic Operators
Arithmetic Operators are used to perform arithmetic on numbers:
Operator Description
+ Addition
- Subtraction
* Multiplication
** Exponentiation (ES2016)
/ Division
% Modulus (Division Remainder)
++ Increment
-- Decrement
JavaScript Comparison Operators
Comparison operators can compare numbers or strings and perform evaluations. Expressions that
use comparison operators do not return a number value as do arithmetic expressions. Comparison
expressions return either 1 , which represents true, or 0 , which represents false.
Operator Description
== equal to
=== equal value and equal type
!= not equal
!== not equal value or not equal type
> greater than
< less than
>= greater than or equal to
<= less than or equal to
? ternary operator
JavaScript Logical Operators
Logical operators are used to combine two or more conditions together and return a single
true/false result. This is useful for creating more complex conditions in our programs. There are
JavaScript
three logical operators: AND, OR, and NOT. The AND operator returns true only if both conditions
being compared are true.
Operator Description
&& logical and
|| logical or
! logical not