0% found this document useful (0 votes)
5 views

JavaScript_BTech_Notes

The document provides an overview of JavaScript data types, categorizing them into primitive (e.g., String, Number, Boolean) and non-primitive types (e.g., Object, Array). It explains how to create an object using object literal syntax and describes the Document Object Model (DOM) and its role in manipulating HTML content. Additionally, it includes examples of validating email and mobile numbers using regular expressions in JavaScript.

Uploaded by

yashu25143
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

JavaScript_BTech_Notes

The document provides an overview of JavaScript data types, categorizing them into primitive (e.g., String, Number, Boolean) and non-primitive types (e.g., Object, Array). It explains how to create an object using object literal syntax and describes the Document Object Model (DOM) and its role in manipulating HTML content. Additionally, it includes examples of validating email and mobile numbers using regular expressions in JavaScript.

Uploaded by

yashu25143
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

JavaScript Basics - B.

Tech Semester Notes

1. What are JavaScript Data Types?

JavaScript data types are divided into two categories:

1. Primitive Data Types:

- String: Text data (e.g., let name = "Alice";)

- Number: Numeric data (e.g., let age = 25;)

- BigInt: Large integers (e.g., let bigNum = 12345678901234567890n;)

- Boolean: true or false (e.g., let isStudent = true;)

- Undefined: Declared but not assigned (e.g., let x;)

- Null: Represents no value (e.g., let value = null;)

- Symbol: Unique identifiers (e.g., let sym = Symbol("id");)

2. Non-Primitive (Reference) Data Types:

- Object: Key-value pairs (e.g., let person = { name: "John", age: 22 };)

- Array: Ordered collection (e.g., let marks = [85, 90, 95];)

- Function: Callable block (e.g., function greet() { console.log("Hello"); })

2. How can you create an object in JavaScript with a simple example?

You can create an object using object literal syntax:

Example:

let student = {

name: "Ravi",
rollNo: 101,

department: "CSE"

};

Accessing properties:

console.log(student.name); // Ravi

3. What is DOM and how is it involved in an HTML webpage?

DOM (Document Object Model) is a tree-like structure created by the browser from the HTML

document.

- Each HTML element is represented as a node.

- JavaScript can use the DOM to change content, styles, and structure.

Example:

<p id="demo">Original Text</p>

<script>

document.getElementById("demo").innerText = "Changed Text";

</script>

4. How to validate email and mobile number using regular expressions in JavaScript?

Email Validation:

function validateEmail(email) {

const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;

return regex.test(email);

}
Mobile Number Validation (10 digits, optional country code):

function validateMobile(number) {

const regex = /^(\+?\d{1,3}[- ]?)?\d{10}$/;

return regex.test(number);

You might also like