Sunday, February 1, 2026

Full Stack Development- Class 2 - Javascript Instructions

 Javascript Instructions

Key Components of JavaScript Instructions

JavaScript instructions are composed of several key elements:

Syntax: This refers to the rules that must be followed for the code to work correctly. Key rules include using keywords correctly, employing proper variable naming conventions, and utilizing semicolons to separate statements (though they are often optional, they are recommended for clarity).

Keywords: These are reserved words with specific meanings that identify a JavaScript action to be performed, such as var, let, const, if, for, function, and return.

Values and Variables: Instructions often involve working with data. Variables (declared with var, let, or const) are used to store data values.

Operators: These are special symbols used to perform operations on values and variables, such as arithmetic (+, -, *, /), assignment (=, +=), comparison (==, ===, >), and logical (&&, ||) operators.

Functions: These are reusable blocks of code that perform a specific task. They can be defined and then called (executed) when needed.

Control Flow: This determines the order in which statements are executed. It includes conditional statements (if/else, switch) and loops (for, while) that allow code to make decisions and repeat actions.

Objects and Arrays: JavaScript works extensively with objects (collections of properties and methods) and arrays (ordered lists of values).

Examples of JavaScript Instructions:

//Declaring a variable
let greeting = "Hello, world!";
//Comments: 
// A single-line comment
/*
   A multi-line comment
*/

// Declare a constant variable
const greeting = "Hello, World!"; 

// Declare a variable using 'let'
let number = 10;

// Use a built-in function to display an alert box
alert(greeting); 

// Use DOM manipulation to change the content of an HTML element with id="demo"
document.getElementById("demo").innerHTML = "I have " + number + " items.";
Variables can be declared by two ways:
var i = 5; 
let j = 7;
Here i is inferred to be an integer. and its function scoped if its declared inside the 
function. Otherwise if its declared globally its having global scope. 
Redeclaration allowed in the same scope.
Whereas let is a keyword that allows declaration of block scoped variables. These can
be hoisted, and result in ReferenceError if accessed before declaration.
While var declarations are hoisted and initialized as undefinedlet and const are hoisted but remain uninitialized in a "Temporal Dead Zone," causing errors if accessed early.
There are various ways of manipulating the pages.
<html>
<head>
<title> Window Title </title>
<meta keywords="personal blog, full stack dev, devops">
<script> .. </script>
<style>...</style>
</head>
<body>
<h1>Header 1</h1>
</body>
</html>
...
...

<img src=""/>
<a href="link">Some text to click </a>
<audio>
<video>
<iframe>
<table></table>
Singleton tags like <img> do not have ending tag.
Tags have properties/attributes
We can define our own tags in frameworks like react.
The attributes of user defined tags are called props.

..
..
Javascript encountered in html is executed if in the form of statements or function calls. 
If 
functions are just defined without being called they just exist.
There is no single entry point for js like main in "c c++ and java".
The statements are executed from top to bottom in the order they are encountered.

This is how a function is defined in js
function add(a , b)
{
return a+b;
}

No comments:

Post a Comment