function in function code example
Example 1: how to make a function
function myFunction(){
console.log('hi')
}
myFunction()
Example 2: function
function list_formation(){
$args = array(,
'post_type' => 'categories',
'posts_per_page' => 20,
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$formations = get_posts(array(
'post_type' => 'formations',
'post__in' => array(16061),
'meta_query' => array(
array(
'key' => 'categories',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE'
)
)
));
if($formations){
foreach ($formations as $categorie){
echo the_title() . '</br>';
}
}
endwhile;
wp_reset_postdata();
Example 3: javascript function
function calcAge1(birthYear) {
return 2037 - birthYear;
}
const age1 = calcAge1(1991);
const calcAge2 = function (birthYear) {
return 2037 - birthYear;
}
const age2 = calcAge2(1991);
const calcAge3 = birthYear => 2037 - birthYear;
const age3 = calcAge3(1991);
console.log(age3);