javascript
javascript
(JAVA SCRIPT)
Faculty Name: Palak Shandil
Assistant Professor
Operat Description
or
== equal to
=== equal value and equal type Operator Description
!= not equal && logical and
!== not equal value or not equal
type || logical or
> greater than ! logical not
< less than
>= greater than or equal to
<= less than or equal to
? ternary operator
Department of Computer Science and Engineering
� JavaScript Bitwise Operators
� Bit operators work on 32 bits numbers.
� Any numeric operand in the operation is converted into a 32 bit number. The
result is converted back to a JavaScript number.
Operator Description Example Same as Result Decimal
� JavaScript If statement
� It evaluates the content only if expression is true. The signature of JavaScript if statement is given
below.
1. if(expression){
2. //content to be evaluated
3. }
� JavaScript Objects
� A javaScript object is an entity having state and behavior (properties and method). For example:
car, pen, bike, chair, glass, keyboard, monitor etc.
� JavaScript is an object-based language. Everything is an object in JavaScript.
1. <script>
2. var emp=new Object();
3. emp.id=101;
4. emp.name="Ravi Malik";
5. emp.salary=50000;
6. document.write(emp.id+" "+emp.name+" "+emp.salary);
7. </script>
1 Object.assign() This method is used to copy enumerable and own properties from a source
object to a target object
2 Object.create() This method is used to create a new object with the specified prototype object
and properties.
3 Object.defineProperty() This method is used to describe some behavioral attributes of the property.
4 Object.defineProperties() This method is used to create or configure multiple object properties.
5 Object.entries() This method returns an array with arrays of the key, value pairs.
6 Object.freeze() This method prevents existing properties from being removed.
7 Object.getOwnPropertyDescriptor() This method returns a property descriptor for the specified property of the
specified object.
8 Object.getOwnPropertyDescriptors() This method returns all own property descriptors of a given object.
9 Object.getOwnPropertyNames() This method returns an array of all properties (enumerable or not) found.
10 Object.getOwnPropertySymbols() This method returns an array of all own symbol key properties.
11 Object.getPrototypeOf() This method returns the prototype of the specified object.
12 Object.is() This method determines whether two values are the same value.
13 Object.isExtensible() This method determines if an object is extensible
14 Object.isFrozen() This method determines if an object was frozen.
15 Object.isSealed() This method determines if an object is sealed.
16 Object.keys() This method returns an array of a given object's own property names.
17 Object.preventExtensions() This method is used to prevent any extensions of an object.
18 Object.seal() This method prevents new properties from being added and marks all existing
Department of Computer Science and Engineering
properties as non-configurable.
19 Object.setPrototypeOf() This method sets the prototype of a specified object to another object.
20 Object.values() This method returns an array of values.
� JavaScript Array
� JavaScript array is an object that represents a collection of similar type of elements.
� There are 3 ways to construct array in JavaScript
1. By array literal
2. By creating instance of Array directly (using new keyword)
3. By using an Array constructor (using new keyword)
1) JavaScript array literal
� The syntax of creating array using array literal is given below:
var arrayname=[value1,value2.....valueN];
1. <script>
2. var emp=["Sonoo","Vimal","Ratan"];
3. for (i=0;i<emp.length;i++){
4. document.write(emp[i] + "<br/>");
5. }
6. </script>
mouseover onmouseover When the cursor of the mouse comes over the element
mousedown onmousedown When the mouse button is pressed over the element
mouseup onmouseup When the mouse button is released over the element
Form Event:
� <!DOCTYPE html>
� <html>
� <body>
� <h2>JavaScript Prompt</h2>
� <p id="demo"></p>
� <script>
� function myFunction() {
� let text;
� } else {
� }
� document.getElementById("demo").innerHTML = text;
� }
� </script>
� </body>
� </html>
Department of Computer Science and Engineering
How to validate a form using Javascript
� <!DOCTYPE html>
� <html>
� <head>
� <script>
� function validateForm() {
� let x = document.forms["myForm"]["fname"].value;
� if (x == "") {
� alert("Name must be filled out");
� return false;
� }
� }
� </script>
� </head>
� <body>
� <h2>JavaScript Validation</h2>
� <form name="myForm" action="/action_page.php" onsubmit="return validateForm()" method="post">
� Name: <input type="text" name="fname">
� <input type="submit" value="Submit">
� </form>
� </body>
� </html>