DEV Community

Cover image for From Zero to Script: My First Day Learning JavaScript
Sevaki Rajasekar
Sevaki Rajasekar

Posted on

From Zero to Script: My First Day Learning JavaScript

Hi all! Welcome to my another blog. Today I had a intro session about Java Script. SO I am going to share about that content today.

Data types:

=> String - Represents textual data.
Example: "Hello"
=> Number - Represents numbers (both integers and floating-point).
Example: 42, 3.14
=> Boolean Represents logical values: true or false
=> Undefined - A variable that has been declared but not assigned a value.
Example: let x;
=> Null - Represents an intentional absence of any object value.
Example: let x = null;
=> Symbol - Unique and immutable value, often used as object keys.
=> BigInt - Used for very large integers beyond the Number type.
Example: 1234567890123456789012345678901234567890n

Image description

'typeof' Operator:

You can check the type of any variable using typeof.
typeof "hello" // "string"
typeof 42 // "number"
typeof true // "boolean"
typeof undefined // "undefined"
typeof null // "object" (this is a known bug in JavaScript)
typeof {} // "object"
typeof [] // "object"
typeof function(){} // "function"

Variables:

Variables are containers for storing data values.
In JavaScript, you can declare variables using:
- var (old way – avoid using now)
- let (preferred for changeable values)
- const (preferred for fixed values)

Assignment operator:

The assignment operator is used to assign values to variables.
Ex:
let x = 5;
Here, = is the assignment operator.
It assigns the value 5 to the variable x.

DOM:

DOM stands for Document Object Model.
It is a way for your browser to understand and represent an HTML page as a tree structure — where every element (like headings, paragraphs, buttons) is a node or an object.
So, about DOM we have a deep discussion for tomorrow.

How to use this in HTML file?

You can use JavaScript in an HTML file in three main ways:

Inline JavaScript:
You write JavaScript directly inside an HTML tag using the onclick, onmouseover, etc.
Ex:
<button onclick="alert('Hello!')">Click Me</button>

  • Used for very small actions.
  • Not recommended for large or professional projects.

Internal JavaScript:
You write JavaScript inside a <script> tag in the same HTML file, usually in the <head> or at the end of <body>.
Ex:
<!DOCTYPE html>
<html>
<head>
<title>Internal JS</title>
<script>
function showMessage() {
alert("Hello from internal script!");
}
</script>
</head>
<body>
<button onclick="showMessage()">Click Me</button>
</body>
</html>

  • Good for small pages.
  • Becomes messy if code is long.

External JavaScript:
You write JavaScript in a separate .js file and link it to the HTML using the <script src=""> tag.
Ex:
HTML file:
<!DOCTYPE html>
<html>
<head>
<title>External JS</title>
<script src="script.js"></script>
</head>
<body>
<button onclick="showMessage()">Click Me</button>
</body>
</html>

Script.js file:
function showMessage() {
alert("Hello from external file!");
}

  • Best practice for big projects.
  • Clean, reusable, and easier to manage.

So this is all about my first day Java script class.Here after I will frequently update about my classes. Thank you for reading my blog.

Taught by:
@payilagam_135383b867ea296

Top comments (4)

Collapse
 
vigneshwaralingam profile image
Vigneshwaralingam

Is Regex a Data type?

Collapse
 
sevaki_rajasekar_700822f9 profile image
Sevaki Rajasekar

No, it's not considered as data type like String and Number. It is a built in Object. That's why I put it in a Non-primitive data type.

Collapse
 
vigneshwaralingam profile image
Vigneshwaralingam

ok.

Collapse
 
uzzy412_73 profile image
Alexandru Ene

Good Job! Keep going!