0% found this document useful (0 votes)
3 views7 pages

JavaScript Quick Revision Yasir

This document is a quick revision guide for JavaScript, covering essential concepts such as alerts, variables, math expressions, control structures (if statements, loops), arrays, functions, and the Document Object Model (DOM). It provides examples for each topic, illustrating how to use JavaScript effectively. The guide serves as a concise reference for beginners and experienced developers alike.

Uploaded by

khanyyasir40
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

JavaScript Quick Revision Yasir

This document is a quick revision guide for JavaScript, covering essential concepts such as alerts, variables, math expressions, control structures (if statements, loops), arrays, functions, and the Document Object Model (DOM). It provides examples for each topic, illustrating how to use JavaScript effectively. The guide serves as a concise reference for beginners and experienced developers alike.

Uploaded by

khanyyasir40
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JavaScript Quick Revision Guide

1. Alerts
alert("Hello, World!");

2. Variables for Strings


let name = "Yasir";

3. Variables for Numbers


let age = 25;

4. Variable Names Legal and Illegal


Legal: userName, _score, $value
Illegal: 1stName, var, user-name

5. Math Expressions: familiar operators


+, -, *, /, %

6. Math Expressions: unfamiliar operators


++, --

7. Math Expressions: eliminating ambiguity


let result = (2 + 3) * 4;

8. Concatenating text strings


let fullName = "Yasir" + " Khan";

9. Prompts
let name = prompt("Enter your name:");

10. if statements
if (age > 18) {
alert("Adult");
}

11. Comparison operators


==, ===, !=, >, <, >=, <=
JavaScript Quick Revision Guide

12. if...else and else if statements


if (age < 13) {
alert("Child");
} else if (age < 20) {
alert("Teen");
} else {
alert("Adult");
}

13. Testing sets of conditions


if (age > 18 && city === "Mardan") { ... }

14. if statements nested


if (age > 18) {
if (city === "Mardan") {
alert("Welcome");
}
}

15. Arrays
let fruits = ["Apple", "Banana"];

16. Arrays: adding and removing elements


[Link]("Orange");
[Link]();

17. Arrays: removing, inserting, and extracting elements


[Link](1, 1);
[Link](0, 2);

18. for loops


for (let i = 0; i < 5; i++) { ... }

19. for loops: flags, Booleans, array length, and breaks


let found = false;
for (...) {
if (x === y) {
JavaScript Quick Revision Guide

found = true;
break;
}
}

20. for loops nested


for (let i = 0; i < 3; i++) {
for (let j = 0; j < 3; j++) {
...
}
}

21. Changing case


[Link]();
[Link]();

22. Strings: measuring length and extracting parts


[Link];
[Link](0, 3);

23. Strings: finding segments


[Link]("abc");

24. Strings: finding a character at a location


[Link](2);

25. Strings: replacing characters


[Link]("old", "new");

26. Rounding numbers


[Link](), [Link](), [Link]();

27. Generating random numbers


[Link]();

28. Converting strings to integers and decimals


parseInt("123");
JavaScript Quick Revision Guide

parseFloat("12.3");

29. Converting strings to numbers, numbers to strings


String(123);
Number("123");

30. Controlling the length of decimals


[Link](2);

31. Getting the current date and time


let now = new Date();

32. Extracting parts of the date and time


[Link](); [Link](); [Link]();

33. Specifying a date and time


let d = new Date("2025-12-31");

34. Changing elements of a date and time


[Link](2025);

35. Functions
function greet() { alert("Hi"); }

36. Functions: passing them data


function greet(name) { alert(name); }

37. Functions: passing data back from them


function sum(a, b) { return a + b; }

38. Functions: local vs. global variables


Variables inside functions = local

39. switch statements: how to start them


switch (value) {
case 1: ...
JavaScript Quick Revision Guide

40. switch statements: how to complete them


default: ...

41. while loops


while (i < 5) { ... }

42. do...while loops


do { ... } while (i < 5);

43. Placing scripts


Put scripts before </body> or use defer.

44. Commenting
// Single line
/* Multi-line */

45. Events: link


<a href="#" onclick="alert('Hi')">Click</a>

46. Events: button


<button onclick="doSomething()">Click</button>

47. Events: mouse


onmouseover, onmouseout

48. Events: fields


onfocus, onblur, onchange

49. Reading field values


let name = [Link]("name").value;

50. Setting field values


[Link]("name").value = "Yasir";

51. Reading and setting paragraph text


JavaScript Quick Revision Guide

[Link] = "New text";

52. Manipulating images and text


[Link] = "[Link]";

53. Swapping images


function changeImg() {
[Link] = "[Link]";
}

54. Swapping images and setting classes


[Link] = "newClass";

55. Setting styles


[Link] = "red";

56. Target all elements by tag name


let ps = [Link]("p");

57. Target some elements by tag name


Loop and match condition

58. The DOM


Document Object Model: all HTML as JS objects

59. The DOM: Parents and children


[Link];
[Link];

60. The DOM: Finding children


[Link][0];

61. The DOM: Junk artifacts and nodeType


Filter only nodeType === 1 for elements

62. The DOM: More ways to target elements


JavaScript Quick Revision Guide

[Link](), querySelectorAll()

63. The DOM: Getting a target's name


[Link];

64. The DOM: Counting elements


[Link]("p").length;

65. The DOM: Attributes


[Link]("src");

66. The DOM: Attribute names and values


[Link]("alt", "desc");

67. The DOM: Adding nodes


[Link](newElement);

68. The DOM: Inserting nodes


[Link](newEl, existingEl);

You might also like