Skip to main content

Chapter -2 Syntax of JavaScript || First Program in JS - Technology369kk

JavaScript Syntax

In this post We are learn about Syntax of JavaScript, JavaScript can be implemented using JS statement that are placed within the <script>... </script> HTML tags in a web page.

You can place the <script> tags, containing your JavaScript, anywhere within you web page, but it it normally recommended that you should be keep it within the head tags.

The <script> tag alert the browser program to start interpreting all the text between these tags as a script. A simple syntax of your JS will appear as follows. 


 <script>
        // Enter JavaScript Code..
 </script>


The Script tag two important attributes: 

  • Language: 
    • That attributes specifice what scripting language you are using Typically, its value will be JS. Although recent versions of HTML(and XHTML, its successor) have phased out the use of this attribute.

  • Type:
    • This attribute is what is now recommended to indicate the scripting language in use and its value should be set to "text/javascript". 
    • So your JS syntax will looks as follows: 
   <script language="javaScript" type="text/javascript">
         // JavaScript Code in Enter
   </script>
   

Your First JavaScript Code:

  • Let us take a simple example for print out "Hello Enter Your Name". For find this program we added an optional HTML cooment that add out JavaScript program/ This is to save out code from a browser that does not support javascript so we add that to prevent reading the end of the HTML comment as a pice of JavaScript code. Next, we call a function "document.write "which write a string into our HTML documents. 

Let's see an example for more understanding. 



<!DOCTYPE html>
<html lang="en">
<head>
    <title>1st Program in JavaScript</title>
    <!-- Include JavaScript Code: -->
    <script language="javaScript" type="text/javascript">

    // JavaScript Code in Enter !!

    document.write("Hello Shailesh Jaiswal");
   
    </script>
</head>

<body>
    <h1>Congratulation!! You write a successfully 1st Program in JavaScript</h1>
</body>
</html>

Finally Output:- Hello Shailesh Jaiswal 


WhiteSpace and Line Breaks:

  • JavaScript igonres spaces, tabs, and newlines that appear in JavaScipt programs. You can use spaces, tabs and newlines freely in your program and you are free to format and indent your programs in a neat and cosistents way that makes the code easy and unerstand. 

Semicolons are Optional : 

  • Simple statements in JS are generally follwed by a semicolon character, just as they are in C, C++, and Java. JavSript, however, allows you to omit this semicolon if your statements are placed on a seprate line. 
  • For Example: 
 <h2>Semicolon are Optinal:</h2>
    <script>
     var a= 10;
     var b= 20;       
    </script>


  • But when formatted in a single line as follows, you must use semicolons: 
    <h2>Semicolon are used correct:</h2>
    <script>

     var a= 10, b= 20;

    </script>
NOTE: It is my personal opinion for you that is good practice in programming life.


Case Sensitivity

  • JavaScript is a case-sensitive language. This means that the language keywords, variables, functions names, and any other identifiers must be always be types with a consistent capitalization of letters. 
  • So the identifies means Date and DATE both are  diffrent meaning in JavaScript. 
  • Note: Care should be taken while writing varaible and functions name in javaScript. 

Comments in JavaScirpt: 

  • JavaScript supports both C-style and C++ style comments. THUS: 
  • Any text between a // and the end of a line is trated as a comment and is ignored by Javascript. 
  • Again any text between the characters /* and */ is treated as a comment. This may span multiple line.
  • JavaScript also reconginze the HTML comment opening sequence <!-- JavaScript treat this is single line comments and just as it does the // comment. 
  • The HTML comment closing sequence --> is not recognized by JS so it should be written as // --> 
 The Following example shows how to use comments in JavaScript: 


    <script>
        // This is the single line comment. It is similar to comments in C++
    /*
        Now, This is the multiline of comment in JavaScript
        It is very simillar to comment in C Programming
     */
    </script>






Comments

Popular posts from this blog

Assignment of ITA/ Information Technology and Application BCA- Technology369kk

Q1. What is  computer Explain basic computer architecture and Difference components.  2. Discuss the use of memory in computer system, Explain memory hierarchy  in details. 3. What is software? Explain difference types of software with explain. 4. Write short notes on the given:- (I) Internet. (II) LAN (Local area network ) (III) Search engine (IV) Web browser  Q 1.What is computer Explain basic computer architecture, Difference components of computer.   Computer :- Computer is defined as an electronic device that takes input data and instructions from the user and after processing them, it generates useful and desired output quickly.   A computer is designed to execute applications and provides a variety of solutions through integrated hardware and software components.                            It is fast and automatic device. It works with the help of programs and represents the d...

C++ and Java Practical All Questions Answers - BCA -Technology369kk

C++ and Java  In this post see most important questions for practical questions given by college all questions with answers . Guys I want to say that this is only for suggested post for your practical please request to you change same alphabets, words or anything  methods name and variables name because if you write all words same then this is copy paste for another peoples.  Used Topics:  Keywords, Variables, Condition Statements, Function , Array, Structure, Pointer.                           In OOPs, Class and Objects, Constructor, Poly morph, Encapsulation, Access Specifiers,                               Inheritance etc.  So, Without Time Lose Come to the Points, let's go start Now:        *************************************************************************  C++ 12 ...

Assignment of PMO (Principal of Management and Organization) - Technology369kk

 ** Assignment Of PMO ** Agenda: -  4 Questions discuss in this post. Question 1. Write a d etails note on selection why it Called. negative process.  Question 2. Write a details note on 'span of control. Question 3. Planning is an essential process, do you agree ? Discuss  Question 4. Write a note on management function. Q 1. Write a d etails note on selection why it called negative process.  Ans :-  Selection is the process of choosing the most suitable candidates out of the several candidates available.          Selection is a negative process because there may be more rejected then those selected in most of the candidates that is called selection is a negative process. → Selection process has the following steps:-  [ A .] Screening of applicants - Based on the screening of applicants only those candidates. It Called further process of selection. Who are found eligible for the job Standards of the the organization. [ B .] S...