0% found this document useful (0 votes)
45 views

Javascript Complete Notes

JS complete notes in english . For the beginners. Really helpful for those who are new to learning JS. JAVASCRIPT.

Uploaded by

pranayprincebeta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
45 views

Javascript Complete Notes

JS complete notes in english . For the beginners. Really helpful for those who are new to learning JS. JAVASCRIPT.

Uploaded by

pranayprincebeta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 40
JAVASCRIPT JavaScript. is an object-oriented language that - allows creation of interactive web pages. JavaScript allows user entries, which are loaded into an HTML form to be processed as required. JavaScript offers several advantages to a Web developer such as a short development cycle, ease of learning, small size scripts and so on. The strength of JavaScript can be easily and quickly used to extend the functionality, of HTML pages, already on a web site. ADVANTAGES OF JAVASCRIPT ADVANTAGES OF dxV¥RO ee An Interpreted Language: JavaScript is an interpreted language, which requires no complication steps. This provides an easy development process. The syntax is completely interpreted by the browser just as it interprets HTML tags. Embedded within HTML: JavaScript does not require any special or separate editor for programs to be written, edited or compiled. It can be written in any text editor like Notepad, along with appropriate HTML tags, and saved as filename.html. HTML file with embedded JavaScript commands can then be read and interpreted by any browser that is JavaScript enabled. Annu Kelley Hartron Skill Centre 12 ¢ Minimal Syntax-Easy to Learn: By learning just a few commands and simple rules of syntax, complete applications can be built using JavaScript. ; / Quick Development: JavaScript does not require time- consuming compilations, scripts can be developed in a short period of time. ; Designed for simple, small program: It is well suited to implement simple, small programs. Such programs can be easily written and executed at an acceptable speed using JavaScript. In addition, they can be easily integrated into a web page. WRITING JAVASCRIPT INTO HTML - JavaScript syntax is embedded into an HTML file. A browser reads HTML files and interprets HTML tags. Since all JavaScript need to be included as an integral part of an HTML document when required, the browser needs to be informed that specific sections of HTML code is JavaScript. The browser will then use its built-in JavaScript engine to interpret this code. The browser is given this information using the HTML tags. . The marks the end of the snippet of scripting code. Annu Kelley Hartron Skill Centre : Syntax: Hartron Skill Centre Hartron Skill Centre Annu Kelley Hartron Skill Centre ENTER BY THE USER The prompt () method displays a dialog box that prompts the visitor for input. A prompt box is often used if we want the user to input a value before entering a page. Coding Output ‘enter the vaive of 2°) [Socument wea) OPERATORS AND EXPRESSIONS IN JAVASCRIPT ¢ An operator is used to transform one or more values into a single resultant value. The value into which the operator is applied is referred to as operands. * A combination of an operator and its operands is referred to as an expression. - Arithmetic operator Logic operator Comparison operator(relational operator) . String operator - Assignment operator Annu Kelley Hartron Skill Centre YERwne Arithmetic operators: Arithmetic operators are the most familiar operators because they are used every day to solve common math calculations. The arithmetic operators that JavaScript supports are: OPERATOR DESCRIPTION + Addition ~ E Subtraction | * Multiplication / Division %_ Modulus ** Exponential +H Increment = Decrement Coding Output Hartron Skill Centre Logical operator: Logical operators are used to perform Boolean Operators on Boolean operands AND, OR, NOT. The logical operators supported by JavaScript are: OPERATOR DESCRIPTION R& Logical AND | ul Logical OR ! Logical NOT Output stitle> Assignment operato! The assignment operator is used to update the value of a variable. Some assignment operators are combined with other operators to perform a computation on the value contained in a variable and then update the variable with the new value. Some’ of the assignment operators supported by JavaScript are: [ Operator Description = Sets the variable on the left of the =operator to the value of the expression on its right = Increments the variable on the left Annu Kelley Hartron Skill Centre orl ya ‘of the +=operator by the value of the expression on its right. Decrements the variable on the left of the -=operator by the value of the expression on the right. | Multiplies the variable on the left of the *=operator by the value of the expression on its right. Ir Divides the variable on the left of | the /=operator by the value of the - expression on its right. = Takes the modulus of the variable on the left of the %-operator using the value of the expression onits right. Coding Output =title> Annu Kelley Hartron Skill Centre ta CONDITION elf ° Ifelse ° If else If If Statement: It evaluates the content only if expression is true. Ques1: write a Program to enter a number if number is greater than 10.then print number is greater than 10 using if condition? Codin; Output * ; ais greater than 10 stitle> If-else statement: Its statement the content whether condition is true or false. Annu Kelley Hartron Skill Centre O,,. S 8 / : ja Ques1: write a program to enter a number if number is greater than 10.then print number is greater than 10 otherwise print number is smaller than 10 using if-else condition? Coding Qutput \ ais smaller than 10 title | Ques2:Write a Program to enter.a percentage and checkout if the percentage is: 80-100% Merit 60-79% Ist division 45-59% 2nd division 33-44% 3rd division Less than 33% Fail J Using if-else-if condition? Annu Kelley Hartron Skill Centre LOOPS Loops in javascript are used to execute the same block of code a specified number of times or while a specified condition is true. Very often when we write code, we want the same block of code to run over and over again. © For loop ¢ While loop * Do-while loop For loop: The for loop is used when we know in advance how many times the script should run. (Initialization; condition; increment) { Code to be executed } Annu Kelley Hartron Skill Centre W hag Ques1: Write a program to print numbers from 1 to 10 Using for loop. Coding Output stitle> =script> vara: for(a=1:a<=10:a4+) document. write(a+" | /nead> | FOMIANAWHH Ques2: Write a Program to print numbers from 10 to 1 using for loop. Coding Output ° stitle> =script> var a, for(a=10;a>=1;a—-) { Gocument.write(a+" FNWEUAVHOK Annu Kelley Hartron Skill Centre 117 Ques3: Write a program to print even numbers upto 100 using for loop? Ques4: Write a program to print odd number upto 99 using for loop? Ques5: Write a program to enter a number if number is divisible by 5 than print counting till that number upto 100. Otherwise print number is not divisible by 5. Using for loop? While loop: The while loop is used when we want the loop to execute and continue executing while the specified condition is true. Initialization; While (condition) { Code to be executed Increment/decrement } Ques1: Write a program to print numbers from 1 to 10 using while loop. Annu Kelley Hartron Skill Centré Output SV SIAWAWHE Ques2: Write a program to print numbers from 10 to 1 using while loop. Coding Output 10 2 i Ques3: Write a program to enter a number if number is sible by 5 than print all divisible. of 5 till that number up Annu Kelley Hartron Skill Centre stl 119 to 100.Otherwise print number is not divisible by 5 using while loop? Ques4: Write a program to print table of any number enter by the user. Using while loop? Do-while-loop: It is variant of while loop. This loop will always execute a block of code once, and then it will repeat the loop as long as specified condition is true. This loop will always be executed at least once, even if the condition is false, because the code is executed before the condition is tested. Initialization; do { Code to be executed Increment } While (condition) Annu Kelley Hartron Skill Centre Coding Output | Seas | The no. isO The no. isl . The no. is10 Ques1: Write a Program to enter two numbers and print counting that numbers. Using do-while loop? ARRAY Annu Kelley Hartron Skill Centre ot\ Coding Output nerds Jenead: citles Jenaodavaseript anrays Access the Elements of an Array: You access an array element by referring to the index number. Coding Output Sleetitles seraysciht> i : iS JavaScript Arrays Serge (or corelsaa3" "volvo econo. getelenentlytat 7 Honeritecars(0}s neat Annu Kelley Hartron Skill Centre ov FUNCTIONS 3 * Function is a set of instructions that are organized to, Perform a particular task. ein javascript, we can execute the function on user actions like when the user clicks the mouse button. * function function name(list of Parameters) { Statement } The function keyword is used for declaring function is. followed by function name. This name is referred whenever function is called, A function can be take Parameters (arguments). These are names of variables in which values are passed to invoke the function. This is your frst day in our institute String object: Methods Description big() The text appear larger as compared to normal blink() The text blinks Bold() Text comes with bold format__| fontcolor (color name) Change the color of font fontsize(size) Change text size Italics() Small() Change text to italics The text appears smaller as compared to normal Strike() Sub() Strikeout the text Subscript the text | Annu Kelley Hartron Skill Centre azl ™ Vv f—5, J Page 129 jp Sul) Superscript the text a toLowerCase() Change to small letter r toUpperCase() Change to capital letter | String as an object, we can manipulate string using methods. Coding Output ein cheae> Pen ‘ties ete tes “ser anguage=avaserpt> funtion dspiayTextst) ‘ Socumentaurter" ‘splay Tent This ent is dglayed using smal Hin tagssral) ‘GeplayText-This tert delayed using big Min! tags bit) bei Sebay Tenens teste smal ete foLowerase() SepiayTextcThs texte eaptal letter toUpperCa5e0h edi TenicTis text ie subsent’ sb) Soba) tenths texts superset 00) 0 S82 Tents texts strike rough” ste: Navigator Object: The Navigator object has properties that convey the browser's information. For example, the user agent is a property of the window navigator object. It is a long string that identifies the web browser. Annu Kelley Hartron Skill Centre Methods Description appCodeName Returns the code name of the browser appName Returns the name of the browser appVersion Returns the version information of the | L browser cookieEnabled Determines whether cookies are ‘| enabled in the browser geolocation Returns a Geolocation object that can be used to locate the user's position language Returns the language of the browser onLine Determines whether the browser is online platform Returns for which platform the browser | is compiled | product Returns the engine name of the browser | userAgent Returns the user-agent header sent by | the browser to the server Coding Output chin Sheag> “le fie>