JavaScript is ascripting language. A scripting language is a light weight programming language.
The sentences in a programming language are called statements.
The principles, how sentences are constructed in a language, are called language syntax.
JavaScript Literals
In a programming language, aliteralis a constant value, like 3.14. Number literalscan be written with or without decimals, and with or without scientific notation (e)
The principles, how sentences are constructed in a language, are called language syntax.
JavaScript Literals
In a programming language, aliteralis a constant value, like 3.14. Number literalscan be written with or without decimals, and with or without scientific notation (e)
<!DOCTYPE html> <html> <body> <p id="demo"></p> <script> document.getElementById("demo").innerHTML = 123e5; </script> </body> </html>
String literals can be written with double or single quotes
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 'John Elwin';
</script>
</body>
</html>
<html>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 'John Elwin';
</script>
</body>
</html>
Expression literal sevaluates (computes) to a value:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 * 10;
</script>
</body>
</html>
<html>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 * 10;
</script>
</body>
</html>
Array literals defines an array:
[40,100,1,5,25,10]
Object literals defines an object:
{firstName:"John",
lastName:"Elwin", age:22,
eyeColor:"blue"}
Function literalsdefines a function: functionmyFunction(a, b) {returna * b;}
lastName:"Elwin", age:22,
eyeColor:"blue"}
Function literalsdefines a function: functionmyFunction(a, b) {returna * b;}