Syntax of JavaScript
JavaScript can be implemented using JavaScript commands that are placed in HTML tags in a web page.
You can place the card
The script tag takes the following two important properties:
Language - This property specifies which scripting language you are using. Its value will be javascript. Although recent versions of HTML (and XHTML) have stopped using this attribute again.
Type - This attribute is what is now recommended to use and its value should be set to "text / javascript".
Here's a snippet of JavaScript:
Your first JavaScript script
Now we make a sample to print "Hello World". We add an arbitrary HTML commet that surrounds JavaScript code. This preserves our code when a browser does not support JavaScript. The comment ends with a "// ->". Here "//" represents a comment in JavaScript, so we add it to prevent a browser from reading the comment as part of JavaScript code. Next, we call a documet.write function that writes a string into our HTML document.
This function can be used to write text, HTML or both. See the following code:
It will produce the following result:
Hello World!
White space and interrupt line
JavaScript ignores new spaces, tabs, and lines that appear in JavaScript programs. You can use free spaces, tabs, and lines in your program and you are free to format and indent your program and the proper way to create code that is easy to read and understand.
The semicolon is optional
Simple commands in JavaScript are generally followed by a semicolon character, which when they are in C, C ++, and Java. However, JavaScript allows you to ignore this semicolon if each of your commands is placed on a separate line. For example, the following code can be written without using a semicolon:
But when formatted in a single line as follows, you must use semicolons:
Note - When practicing, it is better to use semicolons.
Differentiate typefaces
JavaScript is a case-sensitive language. This means that language keywords, variables, function names, and any other identifiers must always be written correctly.
Therefore, the two identifiers TIME and Time will have different meanings in JavaScript.
Note : You should be especially careful when writing function variables and names in JavaScript.
Comments in JavaScript
JavaScript supports both comment styles of C and C ++, so:
Any text between a // and the end of a line is treated as a comment and ignored by JavaScript.
Any text between the / * and * / characters is considered a comment. It can spread over many lines.
JavaScript also recognizes HTML comments with open ranges in HTML comments are not recognized by JavaScript so it should be written as // ->.
For example
The following example shows how to use comments in JavaScript:
Follow tutorialspoint
Previous article: What is JavaScript?
Next lesson: Enable JavaScript in browsers
You should read it
- What is JavaScript?
- What is Currying in Javascript? How to use Currying in JavaScript
- What is JavaScript? Can the Internet exist without JavaScript?
- Top site with many good JavaScript exercises to practice
- Things to know about 'this' in JavaScript
- Tips and tricks that JavaScript programmers need to know
- Summary of JavaScript exercises with sample code
- JavaScript code to generate error charts & graphs
May be interested
- JavaScript location in HTML Filethere is flexibility in providing javascript code anywhere in an html document. however, the most preferred ways to include javascript in an html file.
- How to Turn on JavaScriptjavascript is a language used in many websites to provide additional functionality and access to the user. developers use javascript to deliver a large part of their site's functionality to you, the user. your browser must have javascript...
- What is the difference between Java and JavaScript?although the names of java and javascript seem to be related (javascript seems to be a script in java?), but that's the only similarity. these two languages are not technically related to each other.
- Void keywords in JavaScriptvoid is an important keyword in javascript that can be used as a unary operator before its single operand, which can be in any type. this operator defines an expression to be evaluated without returning a value.
- JavaScript code to generate error charts & graphsthe example below illustrates a sample variance chart created with javascript that incorporates a column chart. you will also get the source code for reference and editing as you wish.
- Introduction to 2D Array - 2-dimensional array in JavaScriptin the following article, we will introduce and show you some basic operations to create and access 2-dimensional arrays - 2d array in javascript. essentially, a 2-dimensional array is a concept of a matrix of matrices - a matrix, used to store information. each 1 element contains 2 separate indexes: row (y) - column and column (x) - column.
- Operator in JavaScriptwe see the following simple expression: 4 + 5 is equal to 9. here 4 and 5 are operands and '+' called operator - operator.
- How to Disable JavaScriptthis wikihow teaches you how to turn off your web browser's javascript support. javascript is responsible for loading dynamic content in webpages, so turning it off can help websites load faster than usual. most web browsers and their...
- Browser compatibility in JavaScriptit is extremely important to understand the differences between different web browsers to handle each one in the best way. therefore, you must know which browser your website is running from so that it can provide a suitable solution.
- How to Use JavaScript Injectionsjavascript injection is a process by which we can insert and use our own javascript code in a page, either by entering the code into the address bar, or by finding an xss vulnerability in a website. note that the changes can only be seen...