AgerNic.com
WEB DEVELOPER SITE, HTML, CSS, PHP, SQL

JavaScript Syntax


JavaScript Tutorial » JavaScript Syntax

JavaScript Syntax is a set of rules that define a structured JavaScript program

Syntax:
Example: This example will show how JS statements look like:
var a, b, c;       // is Declare Variables
a = 5; b = 6;      // is Assign Values
c = a + b;         // is Compute Values


JavaScript Values - example


JS syntax defines two types of values:

JavaScript Literals

1. Numbers are written with or without decimals:

Example:
<!DOCTYPE html>
<html>
<body>

<h2>JavaScript Numbers</h2>

<p>This is an example with Number and this <br />
can be written with or without decimals.</p>

<p id="test"></p>

<script>
document.getElementById("test").innerHTML = 24.67;
</script>

</body>
</html>

 

2. Strings are text, within single or double quotes:

Example:
<!DOCTYPE html>
<html>
<body>

<h1>JavaScript Strings</h1>

<p>Strings are text, within single or double quotes,
<br /> example: </p>

<p id="text"></p>

<script>
document.getElementById("text").innerHTML = 'Jon Bon Jovi';
</script>

</body>
</html>


JavaScript Variables, example

In JS, variables are used to store data values.

An equal sign (=) is used to assign values to variables.

Example: a is defined as a variable, and a is given the value 15:
<!DOCTYPE html>
<html>
<body>

<h1>JS Variables</h1>

<p>(a) is defined as a variable.<br />
and a is assigned the value of 15:</p>

<p id="test"></p>

<script>
var a;
a = 15;
document.getElementById("test").innerHTML = a;
</script>

</body>
</html>


Case Sensitivity in JavaScript - example

JavaScript is case-sensitive.
This means that variables, language keywords, function names, and other identifiers must always be typed with a consistent capitalization of letters.

For example, the variable myVar must be typed myVar not MyVar or myvar

Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript Case Sensitivity</title>
</head>
<body>
<script>
var myVar = "Hi, nice to knoe JavaScript";
console.log(myVar);
console.log(MyVar);
console.log(myvar);
</script>
<p><strong>Note:</strong> Check out the browser console by pressing the f12 key on the keyboard, you'll see a line something like this: "Uncaught ReferenceError: MyVar is not defined".</p>
</body>
</html>




Syntax checker, in html, online, for printing values in console, highlighter vscode, documentation, if statemjent with two conditions, pdf
JavaScript Syntax - javascript tutorial

Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.


0
Online Editor
ONLINE EDITOR

news templates


COLOR PICKER

news templates
This tool makes it easy to create, adjust, and experiment with custom colors for the web.


HTML Templates
news templates
Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.


CSS HTML Layout
news templates
Find here examples of creative and unique website layouts.


Free CSS HTML Menu
news templates
Find here examples of creative and unique website CSS HTML menu.