1. JavaScript Basics

    Set of JavaScript basic syntax to add, execute and write basic programming paradigms in JavaScript.

    On Page Script

    Adding internal JavaScript to HTML
    
    <script type="text/javascript"> //JS code goes here </script>
                    

  2. External JS File

    Adding External JavaScript to HTML
    
    <script src="filename.js"></script>
                    

  3. Functions

    JavaScript Function syntax
    
    function nameOfFunction () {
    // function body
    }
                    

  4. DOM Element

    Changing content of a DOM Element
    
    document.getElementById("elementID").innerHTML = "Hello World!";
                    

  5. Output

    This will print value of a in JavaScript console
    
    console.log(a);
                    

  6. Conditionals Statements

    Conditionals statements are used to perform operations based on some conditions.

    If Statement

    The block of code to be executed, when the condition specified is true.
    
    if (condition) {
    // block of code to be executed if the condition is true
    }
                    

  7. If-else Statement

    If the condition for the if block is false, then else block will be executed.
    
    if (condition) {
    // block of code to be if the condition is true
    } else {
    // block of code to be executed if the condition is false
    }
                    

  8. Else-if Statement

    A Basic if-else ladder
    
    if (condition) {
    // block of code to be executed if condition1 is true
    } else if (condition2) {
    // block of code to be executed if the condition1 is false and condition2 is 
    } else {
    // block of code to be executed if the condition1 is false and condition2 is
    }
                    

  9. Switch Statement

    Switch case statement in JavaScript
    
    switch(expression) {
    case x:
    // code block 
    break;
    case y:
    // code block 
    break;
    default:
    // code block
    }
                    

  10. Iterative Statements (Loops)

    Iterative statement facilitates programmer to execute any block of code lines repeatedly and can be controlled as per conditions added by the programmer.

    For Loop

    For loop syntax in javascript
    
    for (statement 1; statement 2; statement 3) {
    // code block to be executed
    }
                    

  11. While Loop

    Runs the code till the specified condition is true
    
    while (condition) {
    // code block to be executed
    }
                    

  12. Do While Loop

    A do while loop is executed at least once despite the condition being true or false
    
    do {
    // run this code in block
    i++;
    } while (condition);
                    

  13. Strings

    The string is a sequence of characters that is used for storing and managing text data.

    charAt method

    Returns the character from the specified index.
    
    str.charAt(3)
                    

  14. concat method

    Joins two or more strings together.
    
    str1.concat(str2)
                    

  15. index of method

    Returns the index of the first occurrence of the specified character from the string else -1 if not found
    
    str.indexOf('substr')
                    

  16. match method

    Searchers a string for a match against a regular expression.
    
    str.match(/(chapter \d+(\. \d)*)/i;)
                    

  17. replace method

    Searchers a string for a match against a specified string or char and returns a new string by replacing the specified values.
    
    str1.replace(str2)
                    

  18. search method

    Searchers a string against a specified value.
    
    str.search('term')
                    

  19. split method

    Splits a string into an array consisting of substrings.
    
    str.split('\n')
                    

  20. substring method

    Returns a substring of a string containing characters from specified indices.
    
    str.substring(0,5)
                    

  21. Arrays

    The array is a collection of data items of the same type. In simple terms, it is a variable that contains multiple values.

    variable

    Containers for storing data.
    
    var fruit = ["element1", "element2", "element3"];
                    

  22. concat method

    Joins two or more arrays together.
    
    concat()
                    

  23. indexOf method

    Returns the index of the specified item from the array.
    
    indexOf()
                    

  24. join method

    Converts the array elements to a string.
    
    join()
                    

  25. pop method

    Delete the last element of the array.
    
    pop()
                    

  26. reverse method

    This method reverses the order of the array elements.
    
    reverse()
                    

  27. sort method

    Sorts the array elements in a specified manner.
    
    sort()
                    

  28. toString method

    Converts the array elements to a string.
    
    toString()
                    

  29. valueOf method

    returns the relevant Number Object holding the value of the argument passed
    
    valuOf()
                    

  30. Number Methods

    JS math and number objects provide several constant and methods to perform mathematical operations.

    toExponential method

    Converts a number to its exponential form.
    
    toExponential()
                    

  31. toPrecision method

    Formats a number into a specified length
    
    toPrecision()
                    

  32. toString method

    Converts an object to a string
    
    toString()
                    

  33. valueOf method

    Returns the primitive value of a number
    
    valueOf()
                    

  34. Maths Methods

    ceil method

    Rounds a number upwards to the nearest integer, and returns the result
    
    ceil(x)
                    

  35. exp method

    Returns the value of E^x.
    
    exp(x)
                    

  36. log method

    Returns the logarithmic value of x.
    
    log(x)
                    

  37. pow method

    Returns the value of x to the power y.
    
    pow(x,y)
                    

  38. random method

    Returns a random number between 0 and 1.
    
    random()
                    

  39. sqrt method

    Returns the square root of a number x
    
    sqrt(x)
                    

  40. Dates

    Date object is used to get the year, month and day. It has methods to get and set day, month, year, hour, minute, and seconds.

    Pulling Date from the Date object

    Returns the date from the date object
    
    getdate()
                    

  41. Pulling Day from the Date oject

    Returns the hours from the date object
    
    getDay()
                    

  42. Pulling Hours from the Date object

    Returns the hours from the date object
    
    getHours()
                    

  43. Pulling Minutes from the Date object

    Returns the minute from the date oject
    
    getMinutes()
                    

  44. Pulling Seconds from the Date object

    Returns the seconds from the date object
    
    getSeconds()
                    

  45. Pulling Time from the Date object

    Returns the time from the date object
    
    getTime()
                    

  46. Mouse Events

    Any change in the state of an object is referred to as an Event. With the help of JS, you can handle events, i.e., how any specific HTML tag will work when the user does something.

    click

    Fired when an element is clicked
    
    element.addEventListener('click', ()=>{
    // Code to be executed when the event is fired
    });
                    

  47. oncontextmenu

    Fired when an element is right-clicked
    
    element.addEventListener('contextmenu', ()=>{
    // Code to be executed when the event is fired
    });
                    

  48. dblclick

    Fired when an element is double-clicked
    
    element.addEventListener('dblclick', ()=>{
    // Code to be executed when the event is fired
    });
                    

  49. mouseenter

    Fired when an element is entered by the mouse arrow
    
    element.addEventListener('mouseenter', ()=>{
    // Code to be executed when the event is fired
    });
                    

  50. mouseleave

    Fired when an element is exited by the mouse arrow
    
    element.addEventListener('mouseleave', ()=>{
    // Code to be executed when the event is fired 
    });
                    

  51. mousemove

    Fired when the mouse is moved inside the element
    
    element.addEventListener('mousemove', ()=>{
    // Code to be executed when the event is fired 
    });
                    

  52. Keyboard Events

    Keydown

    Fired when the user is pressing a key on the Keyboard
    
    element.addEventListener('Keydown', ()=>{
    // Code to be executed when the event is fired
    });
                    

  53. keypress

    Fired when the user presses the key om the Keyboard
    
    element.addEventListener('Keypress', ()=>{
    // Code to be executed when the event is fired
    });
                    

  54. keyup

    Fired when the user releases a key on the keyboard
    
    element.addEventListener('keyup', ()=>{
    // Code to be executed when the event is fired
    });
                    

  55. Errors

    Errors are thrown by the compiler or interpreter whenever they find any fault in the code, and it can be of any type like syntax error, run-time error, logical error, etc. JS provides some functions to handle the errors.

    try and catch

    Try the code block and execute catch when err is thrown
    
    try {
    Block of code to try
    }
    catch(err) {
    Block of code to handle errors
    }
                    

  56. Window Methods

    Methods that are available from the window object

    alert method

    Used to alert something on the screen
    
    alert()
                    

  57. blur method

    The blur() method removes focus from the current window.
    
    blur()
                    

  58. setInterval

    Keeps executing code at a certain setInterval
    
    setInterval(() =>{
    // Code to be executed
    }, 1000);
                    

  59. setTimeout

    Executes the code after a certain interval of Time
    
    setTimeout(() =>{
    // code to be executed
    }, 1000);
                    

  60. close

    The Window.close() method closes the current window
    
    window.close()
                    

  61. confirm

    The window.confirm() instructs the browser to display a dialog with an optional message, and to wait until the user either confirms or cancels
    
    window.confirm('Are you sure?')
                    

  62. open

    Open a new window
    
    window.open("https: //www.futuristicvision.com");
                    

  63. prompt

    Prompts the user with a text and takes a value. Second parameter is the default value.
    
    var name = prompt("what is your name?", "Dev");
                    

  64. scrollBy
    
    window.scrollBy(100, 0); // Scroll 100px to the right
                    

  65. scrollTo

    Scrolls the document to the specified coordinates.
    
    window.scrollTo(500, 0); // Scroll to horizantal position 500
                    

  66. clearInterval

    Clears the setInterval. var is the value returned by setInterval call
    
    clearInterval(var)
                    

  67. clearTimeout

    Clears the setTimeout. var is the value returned by setTimeout call
    
    clearTimeout(var)
                    

  68. stop

    Stops the further resource loading
    
    stop()
                    

  69. Query/Get Elements

    \ The browser creates a DOM (Document Object Model) whenever a web page is loaded, and with the help of HTML DOM, one can access and modify all the elements of the HTML document.

    querySelector

    Selector to slect first matching element
    
    document.querySelector('css-sslectors')
                    

  70. querySelectorAll

    A selector to select all matching elements
    
    document.querySelectorAll('css-sslectors', ...)
                    

  71. getElementByTagName

    Select elements by tag name?
    
    document.getElementByTagName('element-name')
                    

  72. getElementByClassName

    Select element by class name?
    
    document.getElementByClassName('class-name')
                    

  73. Get Element by Id

    Select an element by its id
    
    document.getElementById('id')
                    

  74. Creating Elements

    create new elements in the DOM

    createElement

    Create a new element
    
    document.createElement('div')
                    

  75. createTextNode

    Create a new text node
    
    document.createTextNode('some text here')