Script languages are programming languages that are mainly used to automate tasks in other programs or at the operating system level. Unlike compiler languages, which must be translated into machine code before they can be executed, scripting languages are executed directly by the operating system or by an interpreter. This means that scripting languages are usually faster to write and test than compiler languages, but also less powerful and usually slower to execute.
Some examples of scripting languages are:
Scripting languages are commonly used for automating system management tasks, building web applications or integrating applications. They are also popular for data processing and data science, as they are usually easy to read and write and provide a variety of libraries and frameworks for these purposes.
JavaScript is a programmable language that is mainly used to design web pages. It is supported by most modern web browsers and can be used to implement functions such as animations, games, forms and other interactive elements on web pages. JavaScript was originally developed by Netscape and is now one of the most widely used programming languages on the Internet. It is a client-side language, which means that it runs on the user's computer rather than on the server, which makes it very fast and allows the user to interact directly with the browser. In our case, we embed JavaScript in HTML.
There are several ways to use JavaScript in an HTML page. One way is to insert the JavaScript code directly into the HTML code by writing it in a <script> tag. Here is an example:
The script tag can also be used in the head of the web page. In this case, the JavaScript code is executed as soon as the page is loaded:
An external JavaScript file can also be used. To do this, the src attribute of the <script> tag must be changed. An example is here
As with most websites, there is also a classic Hello World! programme. In this case, a web page is created and an alert is created by JavaScript in the body. This contains the words "Hello World! The browser creates a small alert window that appears automatically when the web page is opened.
So we have also got to know our first method directly. Later, we will get to know other methods.
There are two types of comments: single-line comments and multi-line comments. Single-line comments start with // and continue until the end of the line. Multi-line comments start with /* and end with */. Everything between the start and end markers is considered to be a comment.
There are two types of comments: single-line comments and multi-line comments. Single-line comments start with // and continue until the end of the line. Multi-line comments start with /* and end with */. Everything between the start and end markers is considered to be a comment.
Names of variables, functions, and other identifiers are case sensitive.
In JavaScript, there are several different data types that are comparable to Java. Some of the most common data types are:
After the declaration, the computer allocates memory space for the content of the variables. When the programme ends, the content of the variables can be deleted again. Computers often waste memory and the programmer must always know exactly what kind of data is stored in which variable to avoid errors. In addition, it is not always clear to the computer what purpose the combination of two data types has, so JavaScript treats all variables as strings when in doubt.
The same basic principles as in Java are also used for calculations. The assignment is made via =.
Various types of calculations are performed using arithmetic operators such as +, -, *, /, and %.
You can also use the “Math” object to perform more advanced calculations:
Note: JavaScript follows the standard order of operations (also known as the PEMDAS rule).
The multiplication (b * c) will be performed before the addition (a +), because multiplication has a higher precedence than addition. You can use parentheses to override the default order of operations and specify the desired order of evaluation.
Here is a list from arithmetic operators from our lectures:
The increment operator (++) is used to increase the value of a variable by one. The operator can be placed before (prefix) or after (postfix) the variable. The decrement operator (--) can also be used to decrease the value of a variable by one. The operator can also be placed before (prefix) or after (postfix) the variable.
The difference between prefix and postfix increment/decrement is the order in which the operation is performed. In the prefix form, the operation is performed before the value of the variable is returned. In the postfix form, the operation is performed after the value of the variable is returned. The difference between prefix and postfix increment/decrement is the order in which the operation is performed. In the prefix form, the operation is performed before the value of the variable is returned. In the postfix form, the operation is performed after the value of the variable is returned.
It's important to note that the increment and decrement operators only work with variables, not with constants or expressions.
Conditional statements are used to perform different actions based on different conditions. It allows to execute a block of code only if a specific condition is met. It again reflects the basics of Java.
Basically there are three types of conditional statements in JavaScript
In all of these examples, condition is a “Boolean” expression that evaluates to either true or false. The code inside the curly braces “{ }” will be executed only if the condition is true
In order compare values we need to use comparison operators, which are listed in the next page.
Comparison operators are used to compare two values and determine whether one is greater than, less than, equal to, or not equal to the other. They are used in conditional statements and loops to control the flow of a program
Here is a list of the common comparison operators from our lecture:
Examples:
Note that the == operator performs type coercion, meaning that it converts the operands to the same type before making the comparison. For example, 2 == '2' returns true because the string '2' is coerced to the number 2 before the comparison. On the other hand, the === operator does not perform type coercion and only returns true if the operands are of the same type and have the same value. (source: https://itnext.io/javascript-type-coercion-implicit-conversion-and-why-to-use-and-avoid-ea9a38ecc777)
In JavaScript, a loop is a control flow statement that allows you to execute a block of code multiple times in a controlled and defined manner. There are several types of loops in JavaScript.
The break statement terminates the current loop, switch, or label statement and transfers program control to the statement following the terminated statement. It includes an optional label that allows the program to break out of a labeled statement. The break statement needs to be nested within the referenced label. The labeled statement can be any block statement; it does not have to be preceded by a loop statement.
A break statement, with or without a following label, cannot be used within the body of a function that is itself nested within the current loop, switch, or label statement that the break statement is intended to break out of. (source: https://developer.mozilla.org)