Skip to main content

LEARN SOME BASIC JAVASCRIPT CODES

 Here are some basic JavaScript codes to get you started:

  1. Hello World:
javascript
console.log("Hello, World!");
  1. Variables and data types:
javascript
// Declaring variables var x = 5; let y = "Hello"; const z = true; // Data types console.log(typeof x); // number console.log(typeof y); // string console.log(typeof z); // boolean
  1. Conditional statements:
javascript
let age = 20; if (age < 18) { console.log("You are not old enough to vote"); } else if (age >= 18 && age <= 65) { console.log("You are eligible to vote"); } else { console.log("You are above the voting age limit"); }
  1. Loops:
javascript
// For loop for (let i = 0; i < 5; i++) { console.log(i); } // While loop let j = 0; while (j < 5) { console.log(j); j++; }
  1. Functions:
javascript
// Function declaration function addNumbers(a, b) { return a + b; } // Function expression let multiplyNumbers = function(a, b) { return a * b; } // Arrow function let divideNumbers = (a, b) => { return a / b; } console.log(addNumbers(2, 3)); // 5 console.log(multiplyNumbers(2, 3)); // 6 console.log(divideNumbers(6, 2)); // 3

These are just some basic examples of JavaScript codes. As you continue to learn and practice, you can explore more advanced concepts like object-oriented programming, array methods, and APIs.

Comments

Popular posts from this blog

Download Radhe Movie (2021) 480p FilmyZilla Full HD, Tamilrockers

In the wake of taking the feared criminal Gani Bhai, ACP Rajveer Shikawat also known as Radhe goes on a manhunt to track down the most well off man of the town furtively running a criminal organization Radhe is an upcoming Indian Hindi-language action film directed by Prabhu Deva and produced by Salman Khan, Sohail Khan and Atul Agnihotri. A remake of 2017 Korean film The Outlaws, the film stars Salman Khan, Disha Patani, Randeep Hooda and Jackie Shroff. Wikipedia Release date: 13 May 2021 (India) Trending Director: Prabhu Deva Based on: The Outlaws; by Kang Yoon-sung Music director: Himesh Reshammiya, Sajid–Wajid, Sanchit Balhara, Devi Sri Prasad Producers: Salman Khan, Atul Agnihotri, Sohail Khan, Nikhil Namit Watch now Also read :- कोरोना के कारण फंगल संक्रमण How to download  Gta 5  Gta 5 download apk Gta 4 Download for pc नए कोविड स्ट्रेन लक्षण मूल से अलग कैसे हैं Karma Book by Sadhguru वैक्सीन के दोनों डोज लगे हों तो भी कोरोना हो सकता है Coronavirus nibandh in hindi ...

MAKE HTTP REQUEST IN Java Script | codes

  You can make an HTTP request in JavaScript using the XMLHttpRequest object or the fetch API. Using XMLHttpRequest : javascript Copy code const xhr = new XMLHttpRequest (); xhr. open ( 'GET' , 'https://example.com/api/data' , true ); xhr. onload = function ( ) { if (xhr. status === 200 ) { const response = JSON . parse (xhr. responseText ); console . log (response); } }; xhr. onerror = function ( ) { console . error ( 'Request error' ); }; xhr. send (); Using fetch : javascript Copy code fetch ( 'https://example.com/api/data' ) . then ( response => response. json ()) . then ( data => console . log (data)) . catch ( error => console . error ( 'Fetch error:' , error)); Both methods allow you to send requests and handle responses, but the fetch API is newer and more streamlined, while XMLHttpRequest is more versatile and supports features like aborting a request.