Quick Contact

    JavaScript Syntax

    JavaScript syntax refers to the set of rules that determine how the programmer constructs and the browser interprets JavaScript programs.

    JavaScript provides 3 places to put the JavaScript code: within body tag, within head tag and external JavaScript file.

    The < script> tag in HTML defines a client-side script like JavaScript. We can add the tags in any of the following locations:

    • Inside the < head> tag
    • Inside the < body> tag
    • In an external file

    JavaScript Example : code between the head tag

    Let’s look at the same example of showing a JavaScript alert dialogue box that is located within the head tag.

    In this example, we’re going to write a function called msg(). To construct a function in JavaScript, use the function name syntax as shown below.

    To invoke a function, you must first work on an event. The onclick event is used to invoke the msg() function.

    < html>  
    < head>  
    < script type="text/javascript">  
    function msg(){  
     alert("Hello DucatIndia");  
    < /script>  
    < /head>  
    < body>  
    < p>Welcome to JavaScript Tutorial

    < form> < input type=”button” value=”click” onclick=”msg()”/> < /form> < /body> < /html>

    JavaScript Example : code between the body tag

    We used JavaScript to generate changing contents in the preceding example. Let’s look at a basic JavaScript implementation that shows an alert dialogue box.

    < script type="text/javascript">  
     alert("Hello DucatIndia");  
    < /script>  

    External JavaScript file

    We can make an external JavaScript file and incorporate it in HTML documents. It allows for code reuse because a single JavaScript file may be used in several HTML pages. It makes the web page load faster.

    The file must be saved with the .js extension.

    JavaScript Values

    JavaScript syntax includes two types of values:

    • Fixed values
    • Variable values

    The fixed values are known as Literals, whereas the changeable values are known as Variables.

    A literal is a type of value in JavaScript that takes the value you supply and converts it to a data value. Within code, 10 and 20 are the literals we supplied and hold the literal 30 after computation.

    JavaScript Operators

    JavaScript operators are symbols which enable us to perform calculations on arithmetic operations. Arithmetic operators (+, -, *, /,%) are used to compute the value, while Assignment operators (=, +=, -=, *=) are used to assign values to the variables.

    During addition and concatenation, we utilized the assignment operator = as well as the arithmetic operator + in the preceding code (joining the strings together).

    JavaScript Expressions

    These are the values, operations, and variables combined. They are utilized to determine the value.

    sum = operand1 + operand2; is the expression used in the code.

    JavaScript Keywords

    These are JavaScript designated terms that have a specific meaning therefore cannot be accessed as identifier. JavaScript, for example, employs the var keyword to specify a variables.

    JavaScript Identifiers

    They are used to identify variables in a script. They adhere to the following guidelines:

    • Identifiers must begin with a letter, a dollar symbol ($), or a dash ( ).
    • Identifiers can only contain letters, numbers, the dollar symbol ($), and the underscore ( ).
    • A keyword cannot be an identification.

    JavaScript Data Types

    JavaScript supports many data types for storing variable values. There are two types: primitive and non-primitive (Reference).

    Copyright 1999- Ducat Creative, All rights reserved.

    Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.