hello world js code example

Example 1: hello world in javascript

// 1. Using console.log()
console.log("Hello World");
// console.log() is used in debugging the code.

// 2. Using alert()
alert("Hello, World!");
// // The alert() method displays an alert box over the current window with the specified message.

// 3. Using document.write()
document.write("Hello, World!");
// // document.write() is used when you want to print the content to the HTML document.

Example 2: Javascript how to run hello world

var msg = "hello world";
console.log(msg);

Example 3: hello world javascript

// Output Hello World! in the console.
console.log("Hello World!");

Example 4: js hello world

let thisIstheSourceObjectforOurhelloWorldCode = {character1:"h",character2:"e",character3:"l",character4:"l",character5:"o",character6:"SPACE",character7:"w",character8:"o",character9:"r",character10:"l",character11:"d"}
let thisIsAnArrayContainingAlltheObjectKeyswhicheachrepresenttheindextoacharacter = Object.keys(thisIstheSourceObjectforOurhelloWorldCode)
let thisisanarraycontainingeachcharacterwegrabbed = []
let thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters = ""
for(let thisisanindexervaluewhereforeachtimeourlooprunsthiswillgoup = 0;thisisanindexervaluewhereforeachtimeourlooprunsthiswillgoup<thisIsAnArrayContainingAlltheObjectKeyswhicheachrepresenttheindextoacharacter.length;thisisanindexervaluewhereforeachtimeourlooprunsthiswillgoup = thisisanindexervaluewhereforeachtimeourlooprunsthiswillgoup + 1){
 let thisistheindexfortheactualvaluefortheobjectthatwegrabbedwiththekey = thisIsAnArrayContainingAlltheObjectKeyswhicheachrepresenttheindextoacharacter[thisisanindexervaluewhereforeachtimeourlooprunsthiswillgoup]
let thisistheactualvaluethatwegrabwiththeindex = thisIstheSourceObjectforOurhelloWorldCode[thisistheindexfortheactualvaluefortheobjectthatwegrabbedwiththekey]
thisisanarraycontainingeachcharacterwegrabbed.push(thisistheactualvaluethatwegrabwiththeindex)
}

for(let thisisanotherindexwherewegothrougheachofourcharacterstoprint = 0;thisisanotherindexwherewegothrougheachofourcharacterstoprint<thisisanarraycontainingeachcharacterwegrabbed.length;thisisanotherindexwherewegothrougheachofourcharacterstoprint = thisisanotherindexwherewegothrougheachofourcharacterstoprint + 1 ){
if(thisisanarraycontainingeachcharacterwegrabbed[thisisanotherindexwherewegothrougheachofourcharacterstoprint] == "h"){
thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters = thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters +"H"
}
if(thisisanarraycontainingeachcharacterwegrabbed[thisisanotherindexwherewegothrougheachofourcharacterstoprint] == "e"){
thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters = thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters +"e"
}
if(thisisanarraycontainingeachcharacterwegrabbed[thisisanotherindexwherewegothrougheachofourcharacterstoprint] == "l"){
thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters = thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters +"l"
}
if(thisisanarraycontainingeachcharacterwegrabbed[thisisanotherindexwherewegothrougheachofourcharacterstoprint] == "o"){
thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters = thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters +"o"
}
if(thisisanarraycontainingeachcharacterwegrabbed[thisisanotherindexwherewegothrougheachofourcharacterstoprint] == "w"){
thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters = thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters +"W"
}
if(thisisanarraycontainingeachcharacterwegrabbed[thisisanotherindexwherewegothrougheachofourcharacterstoprint] == "r"){
thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters = thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters +"r"
}
if(thisisanarraycontainingeachcharacterwegrabbed[thisisanotherindexwherewegothrougheachofourcharacterstoprint] == "d"){
thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters = thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters +"d"
}
if(thisisanarraycontainingeachcharacterwegrabbed[thisisanotherindexwherewegothrougheachofourcharacterstoprint] == "SPACE"){
thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters = thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters +" "
}
}
console.log(thisisthestringweconcatenatetogetheraftergrabbingandtransformingallourcharacters)

Example 5: javascript hello world

console.log("Hello World!");

Example 6: javascript hello world

alert("Hello world");

Tags: