1 / 137

JAVASCRIPT PPT [Autosaved]

React Native has created a lot of excitement in the IT industry because of its cross-platform nature Developers can reuse the code between Android, iOS with minimal effort. AchieversIT institute brings you the opportunity to master React Native and embark on a career that will be the demand of the future<br><br>

Download Presentation

JAVASCRIPT PPT [Autosaved]

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JAVASCRIPT https://www.achiversit.com

  2. https://www.achiversit.com

  3. AchieversIT https://www.achiversit.com

  4. JavaScript is a scripting language mainly used for programming web applications. It is one of the most popular languages in the world also known as JS. • Programs written in JavaScript is generally called a script. JavaScript can control • elements, media, attributes, and other contents on web pages or web applications. • It is mostly used by browsers but many non-browser environments also have support • for JavaScript. For example, Node.js is a JavaScript runtime environment. • JavaScript is an interpreted language. It means that the JavaScript code is executed • by the browser and the browser does not have to compile the code into byte code. • This means that the JavaScript code is executed in real-time. This is a big advantage • of JavaScript over other programming languages like C++, C#, Java, etc. • In frontend development, it is used to make web pages dynamic, create a better user • interface, or create some features. It was originally developed by Netscape in 1995. • JavaScript is integrated with HTML so it's easy to use. It is a very important language • when you are learning web development. https://www.achiversit.com

  5. https://www.achiversit.com

  6. AchieversIT https://www.achiversit.com

  7. AchieversIT • JavaScript is a scripting language and not a programming language. • Programming languages and Scripting languages are very much similar but they have • few differences: https://www.achiversit.com

  8. https://www.achiversit.com

  9. Why learn JavaScript? Without JavaScript, your webpage will be static and unable to perform any task. Using JavaScript you can program your webpage how to behave on events. When you are learning web development then there are three main languages that you must learn: • HTML - It defines the content of a web page. • CSS - It defines the layout and style of a web page. • JavaScript - It provides dynamic behavior to web pages. Interesting facts about JavaScript. • Interesting facts about JavaScript • The first name of JavaScript was Mocha (codename) which was then changed to Live Script and finally changed to JavaScript in the next three months. • JavaScript is one most popular programming languages. • JavaScript was used by Google to build the search engine. • JavaScript was developed in just 10 days. https://www.achiversit.com

  10. https://www.achiversit.com

  11. VARIABLES

  12. let https://www.achiversit.com

  13. https://www.achiversit.com

  14. https://www.achiversit.com

  15. Primitive Data Types https://www.achiversit.com

  16. Non-Primitive Data Type https://www.achiversit.com

  17. https://www.achiversit.com

  18. https://www.achiversit.com

  19. https://www.achiversit.com

  20. https://www.achiversit.com

  21. https://www.achiversit.com

  22. https://www.achiversit.com

  23. https://www.achiversit.com

  24. Conditions • if statement if statement is the most basic conditional statement. It executes a block of code only when the given condition is true. if the condition is false then execution leaves the block and jumps to the next section. let x = 10; if (x == 10) { console.log("Statement is true, x = 10"); } https://www.achiversit.com

  25. https://www.achiversit.com

  26. else if statement • The else if statement is used to execute a block of code when the condition in if • statement is false. • The else if statement is similar to the else statement but it is used to check multiple • conditions. • It is always used after any if statement. • The if-else statement is used to execute a block of code among 2 alternatives while else • if statement gives other alternatives to it. var a = 15; if (a == 10) { console.log("True, a = 10"); } else if (a == 15) { console.log("True, a = 15"); } else { console.log("False, a is not equal to 10 or 15"); } https://www.achiversit.com

  27. switch statement • The switch statement is used to execute a block of code based on a value. • The switch statement is similar to the if statement but it is used to check multiple conditions. • switch statement is a collection of many conditions in an ordered manner that work exactly like if statement. https://www.achiversit.com

  28. let today = new Date().getDay(); switch (today) { case 0: console.log("Sunday!"); break; case 1: console.log("Monday!"); break; case 2: console.log("Tuesday!"); break; case 3: console.log("Wednesday!"); break; case 4: console.log("Thursday!"); break; case 5: console.log("Friday!"); break; default: console.log("Saturday!"); } https://www.achiversit.com

  29. Nested if statements let employee = { name: "herry", age: 32, experience: 6 } if (employee.age > 30) { if (employee.experience > 5) { console.log("Eligible!"); } else { console.log("Not eligible!"); } } else { if (employee.experience > 3) { console.log("Eligible!"); } else { console.log("Not eligible!"); } } The conditional statements can be nested to each other. This means you can write an if statement within another if statement. https://www.achiversit.com

  30. LOOPS What is a loop? • A loop is a control flow statement that is used to execute a block of code over and over • again until the condition given in the loop is true. • In simple words, a loop is a block of code that is executed over and over again until a condition is • met. The condition is called a loop condition and it is given in the loop. • Why do we use loops? • The most common use of loops is to repeat a block of code a number of times. • For example, you might want to print a message a number of times. You can use a • loop to do this. • Loops are very useful while programming, it is one of the most used features of any • programming language. • for example, if we want to print "Hello, World!" 10 times then instead of writing printing • code for 10 times we can use a loop and write the code once. https://www.achiversit.com

  31. https://www.achiversit.com

  32. https://www.achiversit.com

  33. https://www.achiversit.com

  34. AchieversIT https://www.achiversit.com

  35. Nested loops in JavaScript: • so basically what is a nested loop?it can be defined as a loop within a loop or an outer loop embedded with an inner loop. • Why use nested loops? • It is mainly used to print or visualize table, matrix, pattern, or multidimensional array. • Usage of memory is less. • Suitable when the number of iterations is more in a program. for (leti=0; i<=2; i++) { console.log("- First level loop"); for (let j =0; j <=3; j++) { console.log("-- Second level loop"); } } 35 https://www.achiversit.com https://www.achiversit.com

  36. Strings https://www.achiversit.com

  37. https://www.achiversit.com

  38. 1. charAt in JavaScript The charAt() string method in JavaScript returns a character at the specific index of the given string. The charAt() method takes the index value as an argument and returns the corresponding character from the calling string. An index value of a string starts with 0, which means the first character has an index value of 0, the second character has an index value of 1, and so on. 2. charCodeAt in JavaScript (ASCII) The charCodeAt string method in JavaScript returns the Unicode value (between 0 and 65535) of the character present at the given index of the string. Example Unicode value of 'A' is 65. The charCodeAt() method takes an index as an argument and returns the Unicode value of the character present at that index value. https://www.achiversit.com

  39. 3. concat in JavaScript • The concat string method in JavaScript concatenates the passed string in the method to the calling string and • returns the concatenated string as a new string. • The concat() method can take any number of strings as an argument. • If the passed argument is not a string then it converts the argument to string and then concatenates it. 4.endsWith in JavaScript The endsWith string method in JavaScript is used to determines whether the string ends with a specified substring or not. If it ends with a specified string then it returns true, else returns false. The substring to be checked for the ending is passed as the first argument in the method. https://www.achiversit.com

  40. 5. String includes in JavaScript • The includes string method in JavaScript is used determines whether a given substring is present in the calling • string or not. • If the string is present then the method returns true, if not substring is not present then the method returns false. • The matching of includes() method for the string is case-sensitive. • 6. indexOf in JavaScript • The indexOf string method in JavaScript is used to get the index of the first occurrence of a • specified value in a string. • If the character or substring is not present then it returns -1. The search string is case- • sensitive.

  41. 7. String lastIndexOf JavaScript • The lastIndexOf() string method in JavaScript searches the last occurrence of a substring within a string. • The method starts searching from the end of the string for efficiency. • If the substring is not in the given string then it returns -1. 8. match in JavaScript • The match() string method in JavaScript uses a regular expression to match a series of characters within the • calling string. • The method returns the output as an array of string with matched character or strings as its element. • If the parameter passed is not a regular expression then it is implicitly converted to RegExp by using  • new RegExp(regexp). const series = "bdWg2AdjgH4du5jUgT"; // match all capital letters and numbers console.log(series.match(/[A-Z0-9]/g)); https://www.achiversit.com

  42. 9. matchAll in JavaScript • The matchAll() string method in JavaScript is an improved variant of the match() method. • In the match method when the regular expression is used without the g flag then it works fine but with • the g flag, it only returns the matches and not its capturing group. • But the matchAll() method finds all the matching string with its capturing group against the regular • expression. • Instead of returning an array the matchAll() method returns an iterator to all results matching the string. You • will have to explicitly convert it to array using spread operator ([...]) or using Array.from() method. Note: It is compulsory to use g flag with the matchAll() method. const series = "to do or not to do"; // matching "do" and capturing group const array = [...series.matchAll(/d(o)/g)]; console.log(array); console.log(array[0]) 10. repeat in JavaScript • The repeat() method concatenates a passed string by a specified number of times and return it as a new • string. • A number of times string is to be repeated is passed as an argument in the method, where the number lies • between 0 and +Infinity. https://www.achiversit.com

  43. 11. replace in JavaScript • The replace method selects one or all matches from a string and replace it with • a replacement string and return it as new string. • To find the match method use string or regular expression. When a string is passed as an • argument then it select only the first match while when a regular expression is passed • then it selects all the matches. https://www.achiversit.com

  44. 12. replaceAll in JavaScript • The replaceAll method returns a new string after replacing all occurrences of matched • pattern with a replacement string. • Unlike replace() method it replaces all the occurrences whether the given pattern is a • string or a regular expression. • The replacement can be a string to be replaced or a function to be called for each match. • 13. search in JavaScript • The search string method in JavaScript is used to determine whether a pattern exists • within the calling string or not, if it exists then the method returns the index value of the • first match within the string. • The search method uses regex to search for a pattern in a string, if a string is passed to • search for then the method implicitly convert it to regex Example :- const str = "kjhafdbAjdbj"; console.log(str.search(/[A-Z]/g)); https://www.achiversit.com

  45. 14. slice in JavaScript The slice string method in JavaScript extracts a part of the string and returns it as a new string. str.slice( startIndex, [, endIndex]) • The slice() takes 2 arguments, the first argument is the start index for the slicing string and the second argument • is the end of the slicing string, where the second argument is optional. • The default value of endIndex is str.length When the second argument is not passed then the string is sliced • from 'startIndex' to the end of the string. • The slice() method also accepts negative value, where -1 represents the last index • 15. split in JavaScript • The split string method in JavaScript divides the given string intro substring and returns an • array of substrings. • The method takes an argument which is a pattern to be used for dividing the string. str.split(pattern, [, limit]) • If the pattern is an empty string ('') then the method split the string at each character • If the pattern is a string (' ') then the method split the string at each space • If the pattern can be a regular expression. '\n' splits the string at each new line • The limit defines the maximum number of substrings to be returned. If it is 0 then an empty array ([]) is returned.

  46. 16. startsWith in JavaScript • The startsWith string method in JavaScript determines whether a string starts with some given • substring or not. If it starts with the desired string then it returns true else return false. • The search string is passed as the first argument to the method. There is also an optional argument • that defines the position from where the method should start checking. • The startsWith method is case-sensitive. https://www.achiversit.com

  47. 17. substr in JavaScript The substr() string method in JavaScript is used to extract a substring from a string. It returns a part of the string, starting at a specific index and ending after a given number of characters. • startIndex - It specifies the index value from where the substring starts • length - It defines number of characters to be extracted • If the value of startIndex is negative then the index is counted from the end of the string in • opposite direction. If it is NaN then it is treated as 0. • 18. substring in JavaScript • The substring() method extracts a part of string between 2 given index values. It returns a part of the string, starting at a specific index and ending after a given number of characters. str.substring(startIndex, endIndex) • startIndex - It specifies the index value from where the substring starts • endIndex - It specifies the index value from where the substring ends • If endIndex is not specified then it is treated as the last character of the string. • If the value of startIndex is greater than the value of endIndex then value of these two variables is swapped. https://www.achiversit.com

  48. 19. toLowerCase in JavaScript The toLowerCase() string method in JavaScript converts the case of a string to lowercase and returns it as a new string. const sentence = "CARBON emission IS INCREASING DAY BY DAY"; console.log(sentence.toLowerCase()); 20. toUpperCase in JavaScript The toUpperCase string method in JavaScript returns a new string by converting the calling string to uppercase. const sentence = "carbon emission is increasing day by day"; console.log(sentence.toUpperCase()); https://www.achiversit.com

  49. 21. toString in JavaScript The toString() string method in JavaScript returns a string representing the specified object. This method also convert numbers to strings in a different number system. For example you can convert a number to a string in binary system by using toString(2), octal system by using toString(8) and hexadecimal system by using toString(16), etc. const str = new String("hello World!"); console.log(str.toString(str)); //hello World! 22. trim in JavaScript The trim() string method in JavaScript removes whitespaces from both ends of the string. Whitespaces are space, tabs, newline, etc. const str = " AchieversIT "; console.log(str.trim()); // AchieversIT 23. valueOf in JavaScript The valueOf() string method in JavaScript returns the primitive value of a String object. const str = new String("hello world"); console.log(str.valueOf(str)); //hello world https://www.achiversit.com

  50. Arrays What is an Array ? • An array is a collection of values. It is a list of items, where each item has a particular • position in the list. • Array is a very powerful tool in programming. While writing programs and working with • some data collection most of the time you would be dealing with the array. • The array data stored in memory are in a contiguous memory location. This means within • memory there is a contiguous block of memory that stores the array data. So, when you access • any element in an array, you don’t need to jump to another memory location to access the • data. This is called linear access. • In JavaScript, array elements are enclosed in square brackets ([]). https://www.achiversit.com

More Related