---import MyComponent from"./MyComponent.astro";constitems=["Dog","Cat","Platypus"];---<ul>{items.map((item)=>(<li>{item}</li>))}</ul><!-- renders as <div>Hello!</div> --><Element><p>Hello</p><p>Hello!</p></Element>
C#
publicvoidMyTaskAsync(string[] files){ MyTaskWorker worker=newMyTaskWorker(MyTaskWorker); AsyncCallback fooback=newAsyncCallback(MyTask);lock(_sync){if(_myTaskIsRunning)thrownewOperationException("The control is busy.");// one-line comment here AsyncOperation async=Async.CreateOperation(null);bool cancelled; worker.BeginInvoke(files, context, out cancelled); _myTaskIsRunning =true; _myTaskContext = context;}}
C++
#include <iostream>usingnamespace std;intmain(){int first_number, second_number, sum;cout<<"Enter two integers: ";cin>> first_number >> second_number;// sum of two numbers in storedsum= first_number + second_number;// prints sumcout<< first_number <<" + "<< second_number <<" = "<< sum;return0;}
Clojure Script
(ns clojure.examples.hello(:genclass));; This program displays Hello World(defnExample[](println[+123]))(Example):dev-http {8080"public"}:builds{:app{:target:browser:output-dir "public/app/js"
Crystal
# A very basic HTTP serverrequire"http/server"server=HTTP::Server.new do |context| context.response.content_type="text/plain" context.response.print "Hello world, got #{context}"endputs"Listening http://127.0.0.1:8080"server.listen(8080)
package mainimport"fmt"// fibonacci is a function that returns a functionfuncfibonacci()func()int{ f2,f1:=0,1returnfunc()int{ f := f2 f2,f1= f1, f+f1return f}}funcmain(){ f :=fibonacci()for i :=0; i <10; i++{ fmt.Println(f())}}
Handlebars
{# Mixed Django style comment#}<h1>{{#if quotaFull}} Please come back tomorrow.{{/if}}</h1><!-- handlebars example --><ul>{{#each serialList}}<li>{{this}}</li>{{/each}}</ul>
Haskell
putTodo::(Int,String)->IO()putTodo(n, todo)=putStrLn(show n ++": "++ todo)prompt::[String]->IO()prompt todos= do putStrLn "" putStrLn "Current TODO list:" mapM_ putTodo(zip[0..] todos)delete::Int->[a]->Maybe[a]
HTML
<figure ="img":class="class":id="id"><img loading="lazy":alt="alt":src="_ || src"> <!-- Inner comment and another --><p>I finally made it to the public</p><figcaption :if="caption">{{ caption }}</figcaption><figcaption :if="caption">{{ caption }}</figcaption><script>constructor(data){ this.caption= data.caption ||''}</script></figure>
Java
// Importing generic Classes/Filesimport java.io.*;classGFG{// Function to find the biggest of three numbersstaticintbiggestOfThree(int x,int y,int z){return z >(x > y ? x : y)? z :((x > y)? x : y);}// Main driver functionpublicstaticvoidmain(String[] args){int a, b, c; a =5; b =10; c =3;// Calling the above function in mainlargest=biggestOfThree(a, b, c);}}
JavaScript
// import some UI stuffimport{ layout }from'components/layout'// environmentconstENV={scripts:['lol.js'],styles:['lmao.css'],desc:undefined}exportdefaultfunction({val}){constfooo=val.split('\n')// 30pxreturn`<div class='node'></div>`}
JSON5
{// this is a JSON5 snippetauthor:'John Doe <john.doe@gmail.com>',keywords:['json','es5'],version:1.5,keywords:['json','json5'],version:1.7,scripts:{test:'mocha --ui exports --reporter spec',build:'./lib/cli.js -c package.json5',}}
functionfinalize_ref(r::AbstractRemoteRef)# Check if the finalizer is already runifislocked(client_refs)||100# delay finalizer for laterfinalizer(finalize_ref, r)return nothing # really nothingend t =begin;sleep(5);println('done\n');end# lock should always be followed by try Threads.for i =1:10 a[i]= Threads.threadid()endend
Kotlin
(DelicateCoroutinesApi::class)funmain()= runBlocking {valjob= GlobalScope.launch {// root coroutine with launchprintln("Throwing exception from launch")throwIndexOutOfBoundsException()}try{ deferred.await()println("Unreached")}catch(e: ArithmeticException){println("Caught ArithmeticException")}}
Lua
-- This here is a commentfunctionperm(a)local n = table.getn(a)return coroutine.wrap(function()permgen(a, n)end)end-- Another functionfunctionprintResult(a)for i,v in ipairs(a) do io.write(v," ")end io.write("hello")end
Markdown
---title:"Lightning CSS might change our thinking"tags:[ css, design systems ]pubDate:2024-02-12---I'm baby truffaut umami wolf small batch icelandadaptogen. Iceland **chambray** raclette stumptown![Hey](/world.png)> Air plant adaptogen artisan gastropub deep v dreamcatcher> Pinterest intelligentsia gluten-free truffaut.
MDX
import{Chart}from'./snowfall.js'exportconstyear=2023In {year}, the snowfall was above average.It was followed by a warm spring which causedflood conditions in many of the nearby rivers.![Hey](/world.png)> Air plant adaptogen artisan gastropub deep v dreamcatcher> Pinterest intelligentsia gluten-free truffaut.<Chart year={year}color="#fcb32c"/><Elemment {...attr }><p class="epic">Yo</p></Element>
Nim
import std/strformattypePerson= objectname:stringage: Natural # Ensures the age is positiveletpeople=[Person(name:"John",age:45),Person(name:"Kate",age:30)]for person in people:# Type-safe string interpolation,# evaluated at compile time.echo(fmt"{person.name} is {person.age} years old")
Nuemark
I'm baby truffaut umami wolf small batch icelandadaptogen. Iceland **chambray** raclette stumptown// line comment here[head="Foo | Bar | Baz"] - Content first | + | + | + - Content collections | + | + | + - Hot-reloading | + | + | + - AI content generation | + | + | +> This is my blockquote right here[.]* Nothing here to see* This one is a banger ![Hello](/banger.png)[loading="eager"]small:"/img/explainer-tall.png"src:"/img/explainer.png"hidden:truewidth:800
Perl
#!/usr/bin/perluse warnings;usePath::Tiny;# foo/barmy$dir=path('foo','bar');# Iterate over the content of foo/barmy$iter=$dir->iterator;while(my$file=$iter->()){# Print out the file name and path print "$file";}
# function definitiondeffind_square(num):result= num * numreturn result'''This is a multiline comment'''square=find_square(3)print('Square:', square)
Ruby
# line comment heredefget_numbers_stack(list)stack=[[0,[]]]output=[] =begin Ruby multiline comments are pretty weirdoes Or maybe not?? =enduntil stack.empty? index,taken= stack.popnext output << taken ifindex== list.size stack.unshift[index +1, taken] stack.unshift[index +1, taken +[list[index]]]end outputend
Rust
usestd::fmt::{ Debug, Display };// all drinks are emptiedfn compare_prints<T: Debug + Display>(t:&T){println!("Debug: `{:?}`", t);}fn compare_types<T: Debug,U: Debug>(t:&T, u:&U){println!("t: `{:?}`", t);}
Shell
#!/bin/bashmyfile='cars.txt'touch $myfileif[-f $myfile ];then rm cars.txt echo "$myfile deleted"fi# open demo on the browseropen "http://localhost:8080"
SQL
SELECTdate_trunc('week', orderdate),count(1)FROM ordersWHERE orderdate between '2024-01-01'AND'2024-02-01'RANK()OVER(ORDERBY __ order_amount DESC)INNERJOIN payment_status p ON o.status_id= p.id;
<script>// line commentimport Info from'./Info.svelte';constpkg={name:'svelte',version:3,speed:'blazing',website:'https://svelte.dev'};</script><!-- layout goes here --><p>These styles...</p><Nested /><Info {...pkg}/><style> /* CSS comment */ p {color: purple;font-family:'Comic Sans MS', cursive;font-size:2em;}</style>
TOML
# This is a TOML documenttitle="TOML Example"[]name="Tom Preston-Werner"dob=1979-05-27T07:32:00-08:00[]enabled=trueports=[8000,8001,8002]data=[["delta","phi"],[3.14]]temp_targets={cpu=79.5,case=72.0}
TypeScript
// user interfaceinterface User {name:string;id:number;}// account interfaceclass UserAccount {name:string;id:number;constructor(name:string,id:number){ this.name= name; this.id= id;}}constuser:User=newUserAccount("Murphy",1);
ZIG
conststd=("std");constparseInt= std.fmt.parseInt;test "parse integers"{constinput="123 67 89,99";constally= std.testing.allocator;// Ensure the list is freed at scope exitdefer list.deinit();varit= std.mem.tokenizeAny(u8, input," ,");while(it.next())|num|{const n =tryparseInt(u32, num,10);try list.append(n);}constexpected=[_]u32{123,67,89,99};for(expected, list.items)|exp, actual|{try std.testing.expectEqual(exp, actual);}}