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

COVID-19 pandemic and its impact on the world | Essay

  The COVID-19 pandemic, caused by the novel coronavirus, has had a profound impact on the world since it was first identified in late 2019. The pandemic has spread to almost every country in the world, resulting in millions of deaths and significant economic and social disruptions. The pandemic has led to the implementation of various measures such as lockdowns, travel restrictions, social distancing, and mask-wearing to slow the spread of the virus. These measures have resulted in significant changes to daily life, including remote work and learning, decreased social gatherings, and changes to shopping and leisure activities. The pandemic has also had a significant impact on the global economy, with many businesses and industries facing closures or significant losses. Governments around the world have implemented various economic stimulus measures to mitigate the impact of the pandemic. In addition to the health and economic impacts, the pandemic has also highlighted existing inequal

Increase youtube subscriber in - 2021

Smart Ways To Get More Subscribers on YouTube in 2019 Kalyan result Grow youtube subscribers Video content is leading the way in the content marketing scene (as of 2019). YouTube is currently the leading platform for video blogging (vlogging), video sharing, and video marketing. It is a free platform offered by Google, and many (including me) love it. Facebook and Twitter have recently stepped into the video marketing game, but they still fall way short of having the kind of impact that YouTube has. Popular: How to make money on YouTube (from beginner to advanced) If you currently have a YouTube channel, you must be wondering how you can get more YouTube subscribers, and how you can increase the reach of your YouTube videos. With over a billion unique YouTube visitors per month, there is a large potential audience for every uploaded video. Whether it’s a video of someone performing a prank or a video of a fashionista’s summerwear review, YouTube is the go-to platform for video

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.