Thursday, May 20, 2021

Javascript runs before HTML even if at end of body

 My javascript is running before my HTML loads, even if I put it right before the like this:

<body>
    <h1>Title</h1>
    <script>
        alert("yo");
    </script>
</body>

Any ideas why that may be happening?


learn javascript

Functional switch statement in Javascript

Say I have a switch statement that takes a variable myData between 1 and some larger value, i.e. 300.


Depending on the "status code" variable, the result is the text value of another variable. For example, if myData == 1, I want to return the a variable called code1. If myData == 300, I want to return the a variable called code300. Code1 and code300 variables store unrelated strings, i.e. "This is a summary", or "This is a note". Some psuedo-code below:


var myData = statusCode;


var code1 = "This is a summary";

var code300 = "This is a note";


switch(myData) {

    case statusCode:

        scriptletResult = returnCode("code", statusCode); // code1 if myData == 1

        break;          

    default:

        scriptletResult = code1;

}


function returnCode(code, statusCode) {

    return code + statusCode; // Returns a variable "code1" if statusCode == 1

}

How can I get this to work?

What is JavaScript?

 

What is JavaScript?

JavaScript may be a language of programming that's liable for providing more interactivity and dynamism to sites . When JavaScript runs within the browser, you don’t got to use a compiler. The browser reads the code directly, without the necessity for third parties. Therefore, it's recognized together of the three mother tongues of the online along side HTML (content and its structure) and CSS (content design and its structure).

Now, JavaScript isn't an equivalent as Java, which may be a very different programing language . The confusion comes from the name, registered by an equivalent company that created Java (Sun Microsystems). JavaScript (JS) was created later, and what the North American company did was simply change the name that its creators had given it when buying the project. The Java programing language has been focused on far more than simply the online since its inception.


read full article here


Features of the JS language

 Features of the JS language The main features of this programming language are: Dynamic typing. That is, the data type will only be determi...