JavaScript

JavaScript

Shokhrukh
  1. alert ("Hello My Name Is Shokhrukh
  2. alert (123) // This is a string
    alert(2+2) // displays 4
  3. var name;
    name = "Shokhrukh"; // Shoulh be declared once
  4. var number = 11 // Number
  5. var number = "11" // A String (word)
  6. var camelCaseMethodOfUsingVariableNames
  7. % gives you remainder e.g. var remainder = 19 % 3 // = 2
  8. num++ // num = num +1; increments by 1
  9. num-- // num = num - 1; decrement by 1
  10. var num = 1;
    var newNum = num-- // newNum=1; num = 0;
    var num = 1;
    var newNum = --num // newNum=0; num= 0;
  11. totalCost = 3 + 3 * 4 //15; But use barantheses. It is better for you e.g. 3+(3*4)
  12. Concatenating:
    alert("Thanks, " + userName + "!");
  13. Prompts are like Alerts:
    var person = prompt("What is your name?", "Your Name"); // Arguments are always strings
  14. if (x === correctAnswer) {} // tripple equal sign
  15. !== // does not equal to smth
  16. if (x === "Vatican") {
    alert("Correct!");
    }
    else if (x==="Rome") {
    alert("Incorrect but close"
    }
    else{
    alert("Incorrect")
    }
  17. You can Chain any number of conditions together:
    if (weight > 300 && time < 6 && age>17 && gender ==="male") {}
  18. if ( SAT>avg || GPA > 2.5 || sport ==="football"){ alert("Welcome")}
    else {} // If any of the given arguments is correct, the code inside the curly brackets is executed
  19. ADD PARANTHESES IF YOU ARE GIVING A LOT OF ARGUMENTS AS IF IT IS MATH
  20. ARRAYS:
    var cities = ["Atlanta", "Baltimore", "Chicago", "Denver", "Los Angeles"]
    alert("Welcome to " + cities[0]); // prints Welcome to Atlanta
  21. ADDING ELEMENTS TO AN ARRAY:
    var cities = [];
    cities[0]= "Atlanta";
    cities[0]="LA"; // And that is how you can replace elements
    cities.pop(); // Removes tha last element
    cities.push("Tashkent, "Termez"); // Add one or more elements to the END of the array
    cities.shift(); // removes and element from the beginning
    cities.unshift("Tashkent", "New York") // Adds two(or more ) to the beginning of an array
    cities.splice(

Report Page